Package io.ebean.util
Class StringHelper
- java.lang.Object
-
- io.ebean.util.StringHelper
-
public class StringHelper extends Object
Utility String class that supports String manipulation functions.
-
-
Constructor Summary
Constructors Constructor Description StringHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
countOccurances(String content, String occurs)
Returns the number of times a particular String occurs in another String.static String[]
delimitedToArray(String str, String delimiter, boolean keepEmpties)
Convert a string that has delimited values (say comma delimited) in a String[].static Map<String,String>
delimitedToMap(String allNameValuePairs, String listDelimiter, String nameValueSeparator)
Parses out a list of Name Value pairs that are delimited together.static boolean
isNull(String value)
Return true if the value is null or an empty string.static HashMap<String,String>
parseNameQuotedValue(String tag)
parses a String of the form name1='value1' name2='value2'.static String
replaceString(String source, String match, String replace)
This method takes a String and will replace all occurrences of the match String with that of the replace String.static String
replaceString(String source, String match, String replace, int additionalSize, int startPos, int endPos)
Additionally specify the additionalSize to add to the buffer.static String
replaceStringMulti(String source, String[] match, String replace)
A search and replace with multiple matching strings.static String
replaceStringMulti(String source, String[] match, String replace, int additionalSize, int startPos, int endPos)
Additionally specify an additional size estimate for the buffer plus start and end positions.static String[]
splitNames(String names)
Splits at any whitespace "," or ";" and trims the result.static String
trimFront(String source, String trim)
Trims off recurring strings from the front of a string.
-
-
-
Constructor Detail
-
StringHelper
public StringHelper()
-
-
Method Detail
-
parseNameQuotedValue
public static HashMap<String,String> parseNameQuotedValue(String tag) throws RuntimeException
parses a String of the form name1='value1' name2='value2'. Note that you can use either single or double quotes for any particular name value pair and the end quote must match the begin quote.- Throws:
RuntimeException
-
countOccurances
public static int countOccurances(String content, String occurs)
Returns the number of times a particular String occurs in another String. e.g. count the number of single quotes.
-
delimitedToMap
public static Map<String,String> delimitedToMap(String allNameValuePairs, String listDelimiter, String nameValueSeparator)
Parses out a list of Name Value pairs that are delimited together. Will always return a StringMap. If allNameValuePairs is null, or no name values can be parsed out an empty StringMap is returned.- Parameters:
allNameValuePairs
- the entire string to be parsed.listDelimiter
- (typically ';') the delimited between the listnameValueSeparator
- (typically '=') the separator between the name and value
-
trimFront
public static String trimFront(String source, String trim)
Trims off recurring strings from the front of a string.- Parameters:
source
- the source stringtrim
- the string to trim off the front
-
isNull
public static boolean isNull(String value)
Return true if the value is null or an empty string.
-
delimitedToArray
public static String[] delimitedToArray(String str, String delimiter, boolean keepEmpties)
Convert a string that has delimited values (say comma delimited) in a String[]. You must explicitly choose whether or not to include empty values (say two commas that a right beside each other.e.g. "alpha,beta,,theta"
With keepEmpties true, this results in a String[] of size 4 with the third one having a String of 0 length. With keepEmpties false, this results in a String[] of size 3.e.g. ",alpha,beta,,theta,"
With keepEmpties true, this results in a String[] of size 6 with the 1st,4th and 6th one having a String of 0 length. With keepEmpties false, this results in a String[] of size 3.
-
replaceString
public static String replaceString(String source, String match, String replace)
This method takes a String and will replace all occurrences of the match String with that of the replace String.- Parameters:
source
- the source stringmatch
- the string used to find a matchreplace
- the string used to replace match with- Returns:
- the source string after the search and replace
-
replaceString
public static String replaceString(String source, String match, String replace, int additionalSize, int startPos, int endPos)
Additionally specify the additionalSize to add to the buffer. This will make the buffer bigger so that it doesn't have to grow when replacement occurs.
-
replaceStringMulti
public static String replaceStringMulti(String source, String[] match, String replace)
A search and replace with multiple matching strings.Useful when converting CRNL CR and NL all to a BR tag for example.
String[] multi = { "\r\n", "\r", "\n" }; content = StringHelper.replaceStringMulti(content, multi, "<br/>");
-
replaceStringMulti
public static String replaceStringMulti(String source, String[] match, String replace, int additionalSize, int startPos, int endPos)
Additionally specify an additional size estimate for the buffer plus start and end positions.The start and end positions can limit the search and replace. Otherwise these default to startPos = 0 and endPos = source.length().
-
splitNames
public static String[] splitNames(String names)
Splits at any whitespace "," or ";" and trims the result. It does not return empty entries.
-
-