Package org.apache.myfaces.util.lang
Class StringUtils
java.lang.Object
org.apache.myfaces.util.lang.StringUtils
Implements utility functions for the String class
Emphasis on performance and reduced memory allocation/garbage collection in exchange for longer more complex code.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringUndoubles the quotes inside the string
Example:static StringUndoubles the quotes inside a substring
Example:static StringdequoteFull(String str, char quote) Removes the surrounding quote and any double quote inside the string
Example:static StringdequoteFull(String str, int begin, int end, char quote) static booleanstatic booleanstatic booleanisFloatNoExponent(String str) Checks that the string represents a floating point number that CANNOT be in exponential notationstatic booleanstatic booleanstatic booleanisNotBlank(String value) static booleanisNotEmpty(String value) static booleanisUnsignedInteger(String str) static intminIndex(int a, int b) Returns the minimum index >= 0, if anystatic StringBufferreplace(StringBuffer out, String s, String repl, String with) static StringBuilderreplace(StringBuilder out, String s, String repl, String with) static Stringstatic Stringstatic String[]splitLongString(String str, char separator) Split a string into an array of strings arround a character separator.static String[]splitLongString(String str, char separator, char quote) Split a string into an array of strings arround a character separator.static String[]splitShortString(String str, char separator) Split a string into an array of strings arround a character separator.static String[]splitShortString(String str, char separator, char quote) Split a string into an array of strings arround a character separator.static Stringstatic String[]
-
Method Details
-
isEmpty
-
isBlank
-
isNotEmpty
-
isNotBlank
-
isFloatNoExponent
Checks that the string represents a floating point number that CANNOT be in exponential notation- Parameters:
str- the string to check- Returns:
- boolean
-
isFloatWithOptionalExponent
-
isInteger
-
isUnsignedInteger
-
dequote
Undoubles the quotes inside the string
Example:
hello""world becomes hello"world
- Parameters:
str- input string to dequotequote- the quoting char- Returns:
- dequoted string
-
dequote
Undoubles the quotes inside a substring
Example:
hello""world becomes hello"world
WARNING: scan for quote may continue to the end of the string, make sure that eithercharAt(end + 1) == quoteorend = str.lentgth(). If in doubt calldequote(str.substring(begin, end), quote)- Parameters:
str- input string from which to get the substring, must not be nullbegin- begin index for substringend- end index for substringquote- the quoting char- Returns:
- dequoted string
- Throws:
IllegalArgumentException- if string is incorrectly quoted
-
dequoteFull
Removes the surrounding quote and any double quote inside the string
Example:
"hello""world" becomes hello"world
- Parameters:
str- input string to dequotequote- the quoting char- Returns:
- dequoted String
-
dequoteFull
-
replace
-
replace
-
replace
-
replace
-
splitLongString
Split a string into an array of strings arround a character separator. This function will be efficient for longer strings- Parameters:
str- the string to be splitseparator- the separator character- Returns:
- array of string subparts
-
splitLongString
Split a string into an array of strings arround a character separator. Each element can be optionally quoted by the quote character.
This function will be efficient for long strings- Parameters:
str- the string to be splitseparator- the separator characterquote- the quote character- Returns:
- array of string subparts
- Throws:
IllegalArgumentException- DOCUMENT ME!
-
splitShortString
Split a string into an array of strings arround a character separator. This function will be efficient for short strings, for longer strings, another approach may be better- Parameters:
str- the string to be splitseparator- the separator character- Returns:
- array of string subparts
-
splitShortString
Split a string into an array of strings arround a character separator. Each element can be optionally quoted by the quote character.
This function will be efficient for short strings, for longer strings, another approach may be better- Parameters:
str- the string to be splitseparator- the separator characterquote- the quote character- Returns:
- array of string subparts
- Throws:
IllegalArgumentException- DOCUMENT ME!
-
substring
-
trim
-
minIndex
public static int minIndex(int a, int b) Returns the minimum index >= 0, if anyUse to find the first of two characters in a string:
minIndex(s.indexOf('/'), indexOf('\'))- Parameters:
a-b-- Returns:
-