Package org.apache.ofbiz.base.util
Class StringUtil
java.lang.Object
org.apache.ofbiz.base.util.StringUtil
Misc String Utility Functions
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A super-lightweight object to wrap a String object. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
addToNumberString
(String numberString, long addAmount) Add the number to the string, keeping (padding to min of original length)static String
cleanHexString
(String str) static String
cleanUpPathPrefix
(String prefix) Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string.static String
convertOperatorSubstitutions
(String expression) Converts operator substitutions (@and, @or, etc) back to their original form.static <K,
V> Map<K, V> Create a Map from a List of keys and a List of valuesstatic char[]
encodeInt
(int i, int j, char[] digestChars) static byte[]
fromHexString
(String str) static String
internString
(String value) static String
join
(Collection<?> col, CharSequence delim) Creates a single string from a Collection of strings separated by a delimiter.static StringUtil.StringWrapper
makeStringWrapper
(String theString) static String
padNumberString
(String numberString, int targetMinLength) static String
removeNonNumeric
(String str) Removes all non-numbers from strstatic String
removeRegex
(String str, String regex) static String
removeSpaces
(String str) Removes all spaces from a stringstatic String
replaceString
(String mainString, String oldString, String newString) Replaces all occurrences of oldString in mainString with newStringSplits a String on a delimiter into a List of Strings.Creates a Map from an encoded name/value pair stringCreates a Map from an encoded name/value pair stringCreates a Map from an encoded name/value pair stringCreates a Map from a name/value pair stringstatic String
toHexString
(byte[] bytes) Reads a String version of a List (should contain only strings) and creates a new ListReads a String version of a Set (should contain only strings) and creates a new Setstatic StringUtil.StringWrapper
wrapString
(String theString)
-
Field Details
-
INSTANCE
-
-
Method Details
-
internString
-
replaceString
Replaces all occurrences of oldString in mainString with newString- Parameters:
mainString
- The original stringoldString
- The string to replacenewString
- The string to insert in place of the old- Returns:
- mainString with all occurrences of oldString replaced by newString
-
join
Creates a single string from a Collection of strings separated by a delimiter.- Parameters:
col
- a collection of strings to joindelim
- the delimiter character(s) to use. (null value will join with no delimiter)- Returns:
- a String of all values in the collection separated by the delimiter
-
split
Splits a String on a delimiter into a List of Strings.- Parameters:
str
- the String to splitdelim
- the delimiter character(s) to join on (null will split on whitespace)- Returns:
- a list of Strings
-
strToMap
Creates a Map from an encoded name/value pair string- Parameters:
str
- The string to decode and formatdelim
- the delimiter character(s) to join on (null will split on whitespace)trim
- Trim whitespace off fields- Returns:
- a Map of name/value pairs
-
strToMap
public static Map<String,String> strToMap(String str, String delim, boolean trim, String pairsSeparator) Creates a Map from a name/value pair string- Parameters:
str
- The string to decode and formatdelim
- the delimiter character(s) to join on (null will split on whitespace)trim
- Trim whitespace off fieldspairsSeparator
- in case you use not encoded name/value pairs strings and want to replace "=" to avoid clashes with parameters values in a not encoded URL, default to "="- Returns:
- a Map of name/value pairs
-
strToMap
Creates a Map from an encoded name/value pair string- Parameters:
str
- The string to decode and formattrim
- Trim whitespace off fields- Returns:
- a Map of name/value pairs
-
strToMap
Creates a Map from an encoded name/value pair string- Parameters:
str
- The string to decode and format- Returns:
- a Map of name/value pairs
-
toList
Reads a String version of a List (should contain only strings) and creates a new List- Parameters:
s
- String value of a Map ({n1=v1, n2=v2})- Returns:
- new List
-
toSet
Reads a String version of a Set (should contain only strings) and creates a new Set- Parameters:
s
- String value of a Map ({n1=v1, n2=v2})- Returns:
- new List
-
createMap
Create a Map from a List of keys and a List of values- Parameters:
keys
- List of keysvalues
- List of values- Returns:
- Map of combined lists
- Throws:
IllegalArgumentException
- When either List is null or the sizes do not equal
-
cleanUpPathPrefix
Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string. -
removeSpaces
Removes all spaces from a string -
toHexString
-
cleanHexString
-
fromHexString
-
encodeInt
public static char[] encodeInt(int i, int j, char[] digestChars) -
removeNonNumeric
Removes all non-numbers from str -
removeRegex
- Parameters:
str
-regex
- Removes all matches of regex from a str
-
addToNumberString
Add the number to the string, keeping (padding to min of original length)- Returns:
- the new value
-
padNumberString
-
convertOperatorSubstitutions
Converts operator substitutions (@and, @or, etc) back to their original form.OFBiz script syntax provides special forms of common operators to make it easier to embed logical expressions in XML
OFBiz XML operators OFBiz operator Substitution @and && @or || @gt > @gteq >= @lt < @lteq <= - Parameters:
expression
- TheString
to convert- Returns:
- The converted
String
-
wrapString
-
makeStringWrapper
-