Class StringUtils
- java.lang.Object
-
- org.wso2.carbon.utils.xml.StringUtils
-
public class StringUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String[]EMPTY_STRING_ARRAYAn empty immutableStringarray.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdeleteCharAndChangeNextCharToUpperCase(String psWord, String psReplace)This method provided a way to delete the given string and change the following first character to capital letter, this is provided because Axis 1.x follow the java naming convenation rather then xml naming convention for there local name.static voidescapeNumericChar(Writer out, String str)write the escaped version of a given stringstatic StringescapeNumericChar(String str)write the escaped version of a given stringstatic booleanisEmpty(String str)Checks if a String is empty ("") or null.static StringmakeQNameToMatchLocalName(String str)This method provides a way to convert the a QName to local name.static String[]split(String str, char separatorChar)Splits the provided text into an array, separator specified.static booleanstartsWithIgnoreWhitespaces(String prefix, String string)Tests if this string starts with the specified prefix (Ignoring whitespaces)static Stringstrip(String str)Strips whitespace from the start and end of a String.static Stringstrip(String str, String stripChars)Strips any of a set of characters from the start and end of a String.static StringstripEnd(String str, String stripChars)Strips any of a set of characters from the end of a String.static StringstripStart(String str, String stripChars)Strips any of a set of characters from the start of a String.static voidunescapeNumericChar(Writer out, String str)Unescapes numeric character references found in theStringto aWriter.static StringunescapeNumericChar(String str)Unescapes numeric character referencs found in theString.
-
-
-
Field Detail
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
An empty immutableStringarray.
-
-
Method Detail
-
startsWithIgnoreWhitespaces
public static boolean startsWithIgnoreWhitespaces(String prefix, String string)
Tests if this string starts with the specified prefix (Ignoring whitespaces)- Parameters:
prefix-string-- Returns:
- boolean
-
split
public static String[] split(String str, char separatorChar)
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A
nullinput String returnsnull.StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a\tb\nc", null) = ["a", "b", "c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]- Parameters:
str- the String to parse, may be nullseparatorChar- the character used as the delimiter,nullsplits on whitespace- Returns:
- an array of parsed Strings,
nullif null String input
-
isEmpty
public static boolean isEmpty(String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = falseNOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
- Parameters:
str- the String to check, may be null- Returns:
trueif the String is empty or null
-
strip
public static String strip(String str)
Strips whitespace from the start and end of a String.
This removes whitespace. Whitespace is defined by
Character.isWhitespace(char).A
nullinput String returnsnull.StringUtils.strip(null) = null StringUtils.strip("") = "" StringUtils.strip(" ") = "" StringUtils.strip("abc") = "abc" StringUtils.strip(" abc") = "abc" StringUtils.strip("abc ") = "abc" StringUtils.strip(" abc ") = "abc" StringUtils.strip(" ab c ") = "ab c"- Parameters:
str- the String to remove whitespace from, may be null- Returns:
- the stripped String,
nullif null String input
-
strip
public static String strip(String str, String stripChars)
Strips any of a set of characters from the start and end of a String. This is similar to
String.trim()but allows the characters to be stripped to be controlled.A
nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is
null, whitespace is stripped as defined byCharacter.isWhitespace(char). Alternatively usestrip(String).StringUtils.strip(null, *) = null StringUtils.strip("", *) = "" StringUtils.strip("abc", null) = "abc" StringUtils.strip(" abc", null) = "abc" StringUtils.strip("abc ", null) = "abc" StringUtils.strip(" abc ", null) = "abc" StringUtils.strip(" abcyx", "xyz") = " abc"- Parameters:
str- the String to remove characters from, may be nullstripChars- the characters to remove, null treated as whitespace- Returns:
- the stripped String,
nullif null String input
-
stripStart
public static String stripStart(String str, String stripChars)
Strips any of a set of characters from the start of a String.
A
nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is
null, whitespace is stripped as defined byCharacter.isWhitespace(char).StringUtils.stripStart(null, *) = null StringUtils.stripStart("", *) = "" StringUtils.stripStart("abc", "") = "abc" StringUtils.stripStart("abc", null) = "abc" StringUtils.stripStart(" abc", null) = "abc" StringUtils.stripStart("abc ", null) = "abc " StringUtils.stripStart(" abc ", null) = "abc " StringUtils.stripStart("yxabc ", "xyz") = "abc "- Parameters:
str- the String to remove characters from, may be nullstripChars- the characters to remove, null treated as whitespace- Returns:
- the stripped String,
nullif null String input
-
stripEnd
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
A
nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is
null, whitespace is stripped as defined byCharacter.isWhitespace(char).StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc"- Parameters:
str- the String to remove characters from, may be nullstripChars- the characters to remove, null treated as whitespace- Returns:
- the stripped String,
nullif null String input
-
escapeNumericChar
public static String escapeNumericChar(String str)
write the escaped version of a given string- Parameters:
str- string to be encoded- Returns:
- a new escaped
String,nullif null string input
-
escapeNumericChar
public static void escapeNumericChar(Writer out, String str) throws IOException
write the escaped version of a given string- Parameters:
out- writer to write this string tostr- string to be encoded- Throws:
IOException
-
makeQNameToMatchLocalName
public static String makeQNameToMatchLocalName(String str)
This method provides a way to convert the a QName to local name. This need to be done is because Axis 1.x follow the java naming convetation for local name rather then xml naming convenation for the local name.
A
nullinput String returnsnull.makeQNameToMatchLocalName("Foo.bar") = fooBar makeQNameToMatchLocalName("Foo.Bar") = fooBar makeQNameToMatchLocalName("FooBar") = fooBar makeQNameToMatchLocalName("Foobar") = fooBar makeQNameToMatchLocalName("fooBar") = fooBar makeQNameToMatchLocalName("foobar") = foobar makeQNameToMatchLocalName("Foo:bar") = fooBar makeQNameToMatchLocalName("Foo-Bar") = fooBar makeQNameToMatchLocalName("Foo-bar") = fooBar makeQNameToMatchLocalName("Foo_bar") = foo_bar makeQNameToMatchLocalName("Foo_Bar") = foo_Bar makeQNameToMatchLocalName("foo:bar") = fooBar- Parameters:
str- the String to parse, may be nullnullsplits on whitespace- Returns:
- String the java naming compliante name
-
deleteCharAndChangeNextCharToUpperCase
public static String deleteCharAndChangeNextCharToUpperCase(String psWord, String psReplace)
This method provided a way to delete the given string and change the following first character to capital letter, this is provided because Axis 1.x follow the java naming convenation rather then xml naming convention for there local name.
A
nullinput String returnsnull.deleteCharAndChangeNextCharToUpperCase("Foo.bar") = fooBar deleteCharAndChangeNextCharToUpperCase("Foo.Bar") = fooBar deleteCharAndChangeNextCharToUpperCase("Foo:bar") = fooBar deleteCharAndChangeNextCharToUpperCase("Foo-Bar") = fooBar deleteCharAndChangeNextCharToUpperCase("Foo-bar") = fooBar deleteCharAndChangeNextCharToUpperCase("Foo_bar") = foo_bar deleteCharAndChangeNextCharToUpperCase("Foo_Bar") = foo_Bar deleteCharAndChangeNextCharToUpperCase("Foo_bar") = foo_bar deleteCharAndChangeNextCharToUpperCase("foo:bar") = fooBar- Parameters:
psWord- the String to be changedreturn nullif null passed.psReplace- the String that need to be eliminated,return null or psWord if psWord is not nullif null passed.- Returns:
- String the java naming compliant name
-
unescapeNumericChar
public static String unescapeNumericChar(String str)
Unescapes numeric character referencs found in the
String.For example, it will return a unicode string which means the specified numeric character references looks like "ようこそ".
- Parameters:
str- theStringto unescape, may be null- Returns:
- a new unescaped
String,nullif null string input
-
unescapeNumericChar
public static void unescapeNumericChar(Writer out, String str) throws IOException
Unescapes numeric character references found in the
Stringto aWriter.For example, it will return a unicode string which means the specified numeric character references looks like "ようこそ".
A
nullstring input has no effect.- Parameters:
out- theWriterused to output unescaped charactersstr- theStringto unescape, may be null- Throws:
IllegalArgumentException- if the Writer isnullIOException- if error occurs on underlying Writer
-
-