public class StringUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
StringUtil.VariableMap
Interface used by
substitute(java.lang.String, editor.search.StringUtil.VariableMap) for variable substitution |
| Modifier and Type | Field and Description |
|---|---|
static int |
ANT_STYLE |
static int |
JAVADOC_LINK_STYLE |
| Constructor and Description |
|---|
StringUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
asStringOrEmpty(Object object)
Returns the toString() of the object or "" if the object is null.
|
static String |
asStringOrNull(Object object)
Returns the toString() of the object or null if the object is null.
|
static String |
asStringOrNullString(Object object) |
static String |
capitalizeFirstChar(String name) |
static boolean |
contains(String s,
String substr)
Return true if string s contains the substring substr
|
static boolean |
containsCaseInsensitive(String s,
String substr)
Return true if string s contains the substring substr (case-insensitive)
|
static String[] |
decodeCSV(String csvFields)
Decodes a string encoded by
encodeCSV(java.util.Iterator) and
returns an array containing the individual string fields. |
static String |
doubleBackslashes(String string)
Replaces any backslashes in a String with two backslashes, in case a
replaceFirst() call is going to consume half of them.
|
static String |
elide(String str,
int maxLength) |
static String |
encodeCSV(Iterator i)
Encode a list of strings as a single CSV encoded string
|
static String |
encodeCSV(List fields)
Encode a list of strings as a single CSV encoded string
|
static String |
encodeDocumentFilenameChars(String strUrl)
Deprecated.
Please use
encodeURLCharacters(java.lang.String) instead |
static String |
encodeSpaces(String strUrl)
Replaces all occurences of space with its escape-sequence "%20".
|
static String |
encodeURLCharacters(String strUrl)
Replaces all occurrences of characters which need to be escaped in a URL.
|
static boolean |
endsWithIgnoreCase(String s,
String suffix)
Returns
true if and only if s ends with
the string prefix, ignoring case. |
static boolean |
equalsIgnoreLineSeparatorDifferences(String s1,
String s2)
Compares two Strings, ignoring line separator differences.
|
static String |
escapeForCSV(char ch)
Converts an escaped character code into a string literal expressing it, i.e.
|
static String |
escapeForCSV(String str)
Escape any special characters in the string, using the CSV escape syntax.
|
static String |
escapeForGosuStringLiteral(String string) |
static String |
escapeForJava(char ch)
Converts an escaped character code into a string literal expressing it, e.g.
|
static String |
escapeForJava(String string)
Escape any special characters in the string, using the Java escape syntax.
|
static void |
escapeForJava(StringBuffer sb)
Like escapeForJava( String ), but escapes the stringbuffer in place.
|
static void |
escapeForJava(Writer out,
String string) |
static String |
escapeForXML(String string)
Escape a string by replacing all occurrences of special characters (such
as > and <) by their corresponding XML entities.
|
static Set |
finalSetOfStrings(String[] members)
Returns an unmodifiable set containing the given strings
|
static String |
formatDuration(long millis)
Pretty print function for formatting a duration.
|
static String |
formatObjectList(List list,
String delimiter)
Simple utility to format an List of objects as a delimited String.
|
static void |
getLocation(String strSource,
int iFrom,
int iTo,
SearchLocation location) |
static String |
heapIntern(String s)
Interns the given string, but unlike string.intern() the strings will be stored
on the heap rather than in perm space, allowing us to later clear out the map if necessary.
|
static String |
htmlEncode(String text) |
static int |
indexOf(CharSequence seq,
char ch)
Returns the index of the specified character in the char sequence.
|
static int |
indexOf(CharSequence seq,
char ch,
int startPos)
Returns the index of the specified character in the char sequence starting at the given start position.
|
static String |
intern(String s)
Make a copy of String before interning to make sure the interned string doesn't have an
overly-large char buffer.
|
static boolean |
isAllowedXMLCharacter(char ch)
Check whether a given character is XML-processor-safe.
|
static <E> StringBuffer |
join(String glue,
Collection<E> charSequences)
Takes a string 'glue' and collection of CharSequences, and returns a StringBuffer containing the CharSequences
joined with the glue between each of them.
|
static StringBuffer |
join(String glue,
String[] strings)
Takes a string 'glue' and array of strings, and returns a StringBuffer containing the strings joined with the glue
between each of them.
|
static StringBuffer |
join(String glue,
String[] strings,
int first,
int last)
Takes a string 'glue' and array of strings, and returns a StringBuffer containing the strings
between the specified indices (inclusive) joined with the glue between each of them.
|
static int |
lastIndexOf(CharSequence seq,
char ch)
Returns the index of the specified character in the char sequence.
|
static int |
lastIndexOf(CharSequence seq,
char ch,
int startPos)
Returns the index of the specified character in the char sequence starting at the given start position.
|
static String |
makeIdentifier(CharSequence name)
Transforms a given name to a legal identifier suitable for Java or
Gosu.
|
static StringBuffer |
postFill(char fillChar,
int minLength,
String string)
Suffixes the given string with the given fillChar so that the string is at least minLength long
|
static StringBuffer |
preFill(char fillChar,
int minLength,
String string)
Prefixes the given string with the given fillChar so that the string is at least minLength long
|
static String |
removeEndChars(String baseString,
String chars)
Deprecated.
use StringUtils.chomp() instead
|
static String |
removeStartAndEndChars(String baseString,
String startChars,
String endChars)
Combination of removeStartChars and removeEndChars.
|
static String |
removeStartChars(String baseString,
String chars)
Removes "chars" from start of baseString if baseString starts with chars.
|
static String |
replaceNonXMLCharacter(char ch) |
static List |
search(String strSource,
String strPattern,
boolean bIgnoreCase) |
static List |
search(String strSource,
String strPattern,
boolean bIgnoreCase,
int iOffset) |
static List |
search(String strSource,
String strPattern,
boolean bIgnoreCase,
int iOffset,
boolean backwards) |
static List |
searchIgnoreCase(String strSource,
String strPattern)
Return a list of
SearchLocations representing the occurrences of the
specified pattern in the specified source string. |
static String |
stackTraceToString(Throwable t) |
static boolean |
startsWithIgnoreCase(String s,
String prefix)
Returns
true if and only if s begins with
the string prefix, ignoring case. |
static String |
stripNewLinesAndExtraneousWhiteSpace(String s) |
static String |
substitute(String pattern,
StringUtil.VariableMap variableMap)
Looks in the pattern string for any variables enclosed in ${}.
|
static String[] |
tokenize(String s,
char separator)
Split up a string into tokens delimited by the specified separator
character.
|
static List<String> |
tokenizeToList(String s,
char separator)
Split up a string into tokens delimited by the specified separator
character.
|
static String[] |
tokenizeUnescaped(String s,
char separator,
char escape)
Split up a string into tokens delimited by the specified separator
character as long as that character is not escaped with the escape character.
|
static String |
toRGBString(Color color) |
static String |
truncateField(String fieldVal,
String delimiter,
int maxLength)
See TruncateFieldTest for examples of this method's usage
|
static String |
xmlEncode(String text) |
public static final int ANT_STYLE
public static final int JAVADOC_LINK_STYLE
public static String[] tokenize(String s, char separator)
s - The String to tokenizeseparator - The character delimiting tokenspublic static List<String> tokenizeToList(String s, char separator)
s - The String to tokenizeseparator - The character delimiting tokenspublic static String[] tokenizeUnescaped(String s, char separator, char escape)
s - The string to tokenize.separator - Character in s denoting separation between tokens.escape - Hint character where the string to tokenize ends.public static String removeStartChars(String baseString, String chars)
baseString - Original stringchars - Characters to remove if foundpublic static String removeEndChars(String baseString, String chars)
public static String removeStartAndEndChars(String baseString, String startChars, String endChars)
public static String substitute(String pattern, StringUtil.VariableMap variableMap)
pattern - the pattern string, must not be nullvariableMap - the variable map used to lookup variable valuespublic static void escapeForJava(Writer out, String string) throws IOException
IOExceptionpublic static String escapeForJava(String string)
public static void escapeForJava(StringBuffer sb)
public static String doubleBackslashes(String string)
public static String escapeForJava(char ch)
ch - Escaped character code.ch is not an escaped character.
Supports Unicode.public static String escapeForXML(String string)
string - the string to be escapedpublic static boolean isAllowedXMLCharacter(char ch)
ch - the character to be checkedpublic static String replaceNonXMLCharacter(char ch)
public static String encodeCSV(List fields)
fields - a non null list of non null objects; their toString method
will be called to convert them to strings (harmless if they are strings)NullPointerException - if fields or any member of fields is nullpublic static String encodeCSV(Iterator i)
i - a non null iterator which should return a series of non null
objects; their toString method will be called to convert them to strings
(harmless if they are strings)NullPointerException - if i or any object returned by i is nullpublic static String[] decodeCSV(String csvFields)
encodeCSV(java.util.Iterator) and
returns an array containing the individual string fields. An empty string
is ambiguous - could be a zero length array or an array containing a single
empty string. This implementation assumes it is an array containing a
single empty stringcsvFields - the encoded fieldsNullPointerException - if csvFields is nullIllegalArgumentException - if csvFields is badly encoded - for example if it contains strings that
contain quotes or commas and they have not been encoded correctlypublic static List searchIgnoreCase(String strSource, String strPattern)
SearchLocations representing the occurrences of the
specified pattern in the specified source string.strSource - A string to search.strPattern - A pattern to search for.public static List search(String strSource, String strPattern, boolean bIgnoreCase, int iOffset)
public static List search(String strSource, String strPattern, boolean bIgnoreCase, int iOffset, boolean backwards)
public static boolean startsWithIgnoreCase(String s, String prefix)
true if and only if s begins with
the string prefix, ignoring case. This method is not null
safe on the second argument.public static boolean endsWithIgnoreCase(String s, String suffix)
true if and only if s ends with
the string prefix, ignoring case. This method is not null
safe on the second argument.public static boolean contains(String s, String substr)
public static boolean containsCaseInsensitive(String s, String substr)
public static void getLocation(String strSource, int iFrom, int iTo, SearchLocation location)
public static String formatObjectList(List list, String delimiter)
list - the list of itemsdelimiter - the delimiter to use between itemspublic static String truncateField(String fieldVal, String delimiter, int maxLength)
public static String encodeSpaces(String strUrl)
strUrl - - string to encodepublic static String encodeURLCharacters(String strUrl)
strUrl - string to encodepublic static String encodeDocumentFilenameChars(String strUrl)
encodeURLCharacters(java.lang.String) insteadstrUrl - string to encodepublic static boolean equalsIgnoreLineSeparatorDifferences(String s1, String s2)
StringUtil.equalsIgnoreLineSeparatorDifferences(null, null) = true
StringUtil.equalsIgnoreLineSeparatorDifferences(null, *) = false
StringUtil.equalsIgnoreLineSeparatorDifferences(*, null) = false
StringUtil.equalsIgnoreLineSeparatorDifferences("abc", "abc") = true
StringUtil.equalsIgnoreLineSeparatorDifferences("abc", "def") = false
StringUtil.equalsIgnoreLineSeparatorDifferences("\r\n", "\n") = true
StringUtil.equalsIgnoreLineSeparatorDifferences("abc\r\ndef", "abc\ndef") = true
StringUtil.equalsIgnoreLineSeparatorDifferences("abc\rdef", "abc\ndef") = false
StringUtil.equalsIgnoreLineSeparatorDifferences("abc\r\ndef\nghi", "abc\ndef\r\nghi") = true
StringUtil.equalsIgnoreLineSeparatorDifferences("abc\r\r\n\ndef", "abc\r\n\r\ndef") = true
public static StringBuffer join(String glue, String[] strings)
glue - The glue stringstrings - The strings to joinpublic static StringBuffer join(String glue, String[] strings, int first, int last)
glue - The glue stringstrings - The strings to joinfirst - The index of the first string to joinlast - The index of the last string to joinpublic static <E> StringBuffer join(String glue, Collection<E> charSequences)
glue - The glue stringcharSequences - The CharSequences to joinpublic static StringBuffer preFill(char fillChar, int minLength, String string)
fillChar - The character to use as prefixminLength - The minimum length of the stringstring - The original stringpublic static StringBuffer postFill(char fillChar, int minLength, String string)
fillChar - The character to use as prefixminLength - The minimum length of the stringstring - The original stringpublic static Set finalSetOfStrings(String[] members)
public static String asStringOrNull(Object object)
public static String asStringOrNullString(Object object)
object - the objectpublic static String asStringOrEmpty(Object object)
public static String escapeForCSV(String str)
public static String escapeForCSV(char ch)
ch - Escaped character codech is not an escaped characterpublic static String intern(String s)
public static String heapIntern(String s)
public static String stripNewLinesAndExtraneousWhiteSpace(String s)
public static String makeIdentifier(CharSequence name)
name - A name that may not already be a legal identifierpublic static int indexOf(CharSequence seq, char ch)
public static int indexOf(CharSequence seq, char ch, int startPos)
public static int lastIndexOf(CharSequence seq, char ch)
public static int lastIndexOf(CharSequence seq, char ch, int startPos)
public static String formatDuration(long millis)
millis - Millis to formatCopyright © 2017. All rights reserved.