|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.tools.StringUtils
public abstract class StringUtils
General purpose class containing common String manipulation
methods.
| Nested Class Summary | |
|---|---|
static class |
StringUtils.BbcodeOption
|
| Field Summary | |
|---|---|
static Pattern |
BBCODE_BAREURL
|
static Pattern |
BBCODE_COLOR
|
static Pattern |
BBCODE_IMG
|
static Pattern |
BBCODE_QUOTE_LONG
|
static Pattern |
BBCODE_SIZE
|
static Pattern |
BBCODE_URL_LONG
|
static Pattern |
BBCODE_URL_SHORT
|
static Charset |
CHARSET_US_ASCII
|
static StringUtils.BbcodeOption |
CONVERT_BARE_URLS
|
static String |
ENCODING_ISO_8859_1
|
static String |
ENCODING_ISO_8859_2
|
static String |
ENCODING_ISO_8859_5
|
static String |
ENCODING_US_ASCII
|
static String |
ENCODING_UTF_16
|
static String |
ENCODING_UTF_16BE
|
static String |
ENCODING_UTF_16LE
|
static String |
ENCODING_UTF_8
|
static StringUtils.BbcodeOption |
NO_FOLLOW_LINKS
|
static StringUtils.BbcodeOption |
SANITIZE_URL
|
static StringUtils.BbcodeOption |
SHORTEN_URL
|
| Constructor Summary | |
|---|---|
StringUtils()
|
|
| Method Summary | |
|---|---|
static String |
capitalize(String source)
Ensure that the first character of the provided string is upper case. |
static String |
convertBbcode(String source)
Converts a BBCode marked-up text to regular html. |
static String |
convertBbcode(String source,
StringUtils.BbcodeOption... options)
Converts a BBCode marked-up text to regular html. |
static String |
convertTabsToSpaces(String line,
int tabWidth)
Converts all tabs on a line to spaces according to the provided tab width. |
static boolean |
convertToBoolean(String value)
Converts a String to a boolean value. |
static int |
count(String source,
String substring)
Counts the number of times a substring occures in a provided string in a case-sensitive manner. |
static int |
count(String source,
String substring,
boolean matchCase)
Counts the number of times a substring occures in a provided string. |
static String |
decodeHtml(String source)
|
static String |
decodeUrlValue(String source)
Decodes a String that has been encoded in a RIFE-specific
manner for URL usage.. |
static boolean |
doesUrlValueNeedDecoding(String source)
Checks if a String is encoded in a RIFE-specific manner
for URL usage. |
static String |
encodeClassname(String name)
Transforms a provided String object into a new string,
containing only valid characters for a java class name. |
static String |
encodeHtml(String source)
Transforms a provided String object into a new string,
containing only valid Html characters. |
static String |
encodeHtmlDefensive(String source)
Transforms a provided String object into a new string,
containing as much as possible Html characters. |
static String |
encodeLatex(String source)
Transforms a provided String object into a new string,
containing only valid LaTeX characters. |
static String |
encodeRegexp(String source)
Transforms a provided String object into a literal that can
be included into a regular expression Pattern as-is. |
static String |
encodeSql(String source)
Transforms a provided String object into a new string,
containing only valid Sql characters. |
static String |
encodeString(String source)
Transforms a provided String object into a new string,
containing only valid String characters. |
static String |
encodeUnicode(String source)
Transforms a provided String object into a series of
unicode escape codes. |
static String |
encodeUrl(String source)
Transforms a provided String object into a new string,
containing only valid URL characters. |
static String |
encodeUrlValue(String source)
Transforms a provided String object into a new string,
only pure US Ascii strings are preserved and URL encoded in a regular
way. |
static String |
encodeXml(String source)
Transforms a provided String object into a new string,
containing only valid XML characters. |
static boolean |
filter(String name,
Pattern[] included,
Pattern[] excluded)
Checks if the name filters through a series of including and excluding regular expressions. |
static boolean |
filter(String name,
Pattern included,
Pattern excluded)
Checks if the name filters through an including and an excluding regular expression. |
static DocumentPosition |
getDocumentPosition(String document,
int characterIndex)
Calculates the DocumentPosition of a character index in a
document. |
static Matcher |
getMatchingRegexp(String value,
Collection<Pattern> regexps)
Matches a collection of regular expressions against a string. |
static Matcher |
getRegexpMatch(Collection<String> values,
Pattern regexp)
Matches a collection of strings against a regular expression. |
static int[] |
indicesOf(String source,
String substring)
Returns an array that contains all the occurances of a substring in a string in the correct order. |
static int[] |
indicesOf(String source,
String substring,
boolean matchCase)
Returns an array that contains all the occurances of a substring in a string in the correct order. |
static String |
join(boolean[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(byte[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(char[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(char[] array,
String seperator,
String delimiter)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(Collection collection,
String seperator)
Creates a new String object, containing the elements of a
supplied Collection of String objects joined
by a given seperator. |
static String |
join(double[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(float[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(int[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(long[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(Object[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(Object[] array,
String seperator,
String delimiter)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(Object[] array,
String seperator,
String delimiter,
boolean encodeStrings)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
join(short[] array,
String seperator)
Creates a new String object, containing the elements of a
supplied array, joined by a given seperator. |
static String |
repeat(String source,
int count)
Creates a new string that contains the provided string a number of times. |
static String |
replace(String source,
String stringToReplace,
String replacementString)
Searches for a string within a specified string in a case-sensitive manner and replaces every match with another string. |
static String |
replace(String source,
String stringToReplace,
String replacementString,
boolean matchCase)
Searches for a string within a specified string and replaces every match with another string. |
static ArrayList<String> |
split(String source,
String seperator)
Splits a string into different parts, using a seperator string to detect the seperation boundaries in a case-sensitive manner. |
static ArrayList<String> |
split(String source,
String seperator,
boolean matchCase)
Splits a string into different parts, using a seperator string to detect the seperation boundaries. |
static String[] |
splitToArray(String source,
String seperator)
Splits a string into different parts, using a seperator string to detect the seperation boundaries in a case-sensitive manner. |
static String[] |
splitToArray(String source,
String seperator,
boolean matchCase)
Splits a string into different parts, using a seperator string to detect the seperation boundaries. |
static byte[] |
splitToByteArray(String source,
String seperator)
Splits a string into bytes, using a seperator string to detect the seperation boundaries in a case-sensitive manner. |
static byte[] |
splitToByteArray(String source,
String seperator,
boolean matchCase)
Splits a string into bytes, using a seperator string to detect the seperation boundaries. |
static int[] |
splitToIntArray(String source,
String seperator)
Splits a string into integers, using a seperator string to detect the seperation boundaries in a case-sensitive manner. |
static int[] |
splitToIntArray(String source,
String seperator,
boolean matchCase)
Splits a string into integers, using a seperator string to detect the seperation boundaries. |
static String |
stripFromEnd(String source,
String stringToStrip)
Removes all occurances of a string from the end of another string in a case-sensitive manner. |
static String |
stripFromEnd(String source,
String stringToStrip,
boolean matchCase)
Removes all occurances of a string from the end of another string. |
static String |
stripFromFront(String source,
String stringToStrip)
Removes all occurances of a string from the front of another string in a case-sensitive manner. |
static String |
stripFromFront(String source,
String stringToStrip,
boolean matchCase)
Removes all occurances of a string from the front of another string. |
static ArrayList<String> |
toArrayList(String[] stringArray)
Creates a new ArrayList, containing the elements of a
supplied array of String objects. |
static String[] |
toStringArray(Iterator<String> iterator)
Creates a new array of String objects, containing the
elements of a supplied Iterator. |
static String |
trim(String source)
Ensures that all whitespace is removed from a String. |
static String |
uncapitalize(String source)
Ensure that the first character of the provided string lower case. |
static String |
wordWrap(String input,
int width,
Locale locale)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static String ENCODING_US_ASCII
public static String ENCODING_ISO_8859_1
public static String ENCODING_ISO_8859_2
public static String ENCODING_ISO_8859_5
public static String ENCODING_UTF_8
public static String ENCODING_UTF_16BE
public static String ENCODING_UTF_16LE
public static String ENCODING_UTF_16
public static Charset CHARSET_US_ASCII
public static final StringUtils.BbcodeOption SHORTEN_URL
public static final StringUtils.BbcodeOption SANITIZE_URL
public static final StringUtils.BbcodeOption CONVERT_BARE_URLS
public static final StringUtils.BbcodeOption NO_FOLLOW_LINKS
public static final Pattern BBCODE_COLOR
public static final Pattern BBCODE_SIZE
public static final Pattern BBCODE_URL_SHORT
public static final Pattern BBCODE_URL_LONG
public static final Pattern BBCODE_IMG
public static final Pattern BBCODE_QUOTE_LONG
public static final Pattern BBCODE_BAREURL
| Constructor Detail |
|---|
public StringUtils()
| Method Detail |
|---|
public static String encodeClassname(String name)
String object into a new string,
containing only valid characters for a java class name.
name - The string that has to be transformed into a valid class
name.
String object.encodeUrl(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeUrl(String source)
String object into a new string,
containing only valid URL characters.
source - The string that has to be transformed into a valid URL
string.
String object.encodeClassname(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeUrlValue(String source)
String object into a new string,
only pure US Ascii strings are preserved and URL encoded in a regular
way. Strings with characters from other encodings will be encoded in a
RIFE-specific manner to allow international data to passed along the
query string.
source - The string that has to be transformed into a valid URL
parameter string.
String object.decodeUrlValue(String),
encodeClassname(String),
encodeUrl(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeLatex(String),
encodeRegexp(String)public static String decodeUrlValue(String source)
String that has been encoded in a RIFE-specific
manner for URL usage.. Before calling this method, you should first
verify if the value needs decoding by using the
doesUrlValueNeedDecoding(String) method.
source - the value that has been encoded for URL usage in a
RIFE-specific way
String object.encodeUrlValue(String),
doesUrlValueNeedDecoding(String)public static boolean doesUrlValueNeedDecoding(String source)
String is encoded in a RIFE-specific manner
for URL usage.
source - the value that might have been encoded for URL usage in a
RIFE-specific way
true if the value is encoded in the RIFE-specific
format; and
false otherwise
encodeUrlValue(String),
decodeUrlValue(String)public static String decodeHtml(String source)
public static String encodeHtml(String source)
String object into a new string,
containing only valid Html characters.
source - The string that has to be transformed into a valid Html
string.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeXml(String),
encodeSql(String),
encodeString(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeHtmlDefensive(String source)
String object into a new string,
containing as much as possible Html characters. It is safe to already
feed existing Html to this method since &, < and > will not
be encoded.
source - The string that has to be transformed into a valid Html
string.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeXml(String),
encodeSql(String),
encodeString(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeXml(String source)
String object into a new string,
containing only valid XML characters.
source - The string that has to be transformed into a valid XML
string.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeSql(String),
encodeString(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeString(String source)
String object into a new string,
containing only valid String characters.
source - The string that has to be transformed into a valid
sequence of String characters.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeUnicode(String source)
String object into a series of
unicode escape codes.
source - The string that has to be transformed into a valid
sequence of unicode escape codes
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeSql(String source)
String object into a new string,
containing only valid Sql characters.
source - The string that has to be transformed into a valid Sql
string.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeString(String),
encodeLatex(String),
encodeRegexp(String)public static String encodeLatex(String source)
String object into a new string,
containing only valid LaTeX characters.
source - The string that has to be transformed into a valid LaTeX
string.
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeString(String),
encodeRegexp(String)public static String encodeRegexp(String source)
String object into a literal that can
be included into a regular expression Pattern as-is. None of the
regular expression escapes in the string will be functional anymore.
source - The string that has to be escaped as a literal
String object.encodeClassname(String),
encodeUrl(String),
encodeUrlValue(String),
encodeHtml(String),
encodeXml(String),
encodeSql(String),
encodeString(String),
encodeLatex(String)
public static int count(String source,
String substring)
source - The String object that will be searched in.substring - The string whose occurances will we counted.
int value containing the number of occurances
of the substring.
public static int count(String source,
String substring,
boolean matchCase)
source - The String object that will be searched in.substring - The string whose occurances will we counted.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
int value containing the number of occurances
of the substring.
public static ArrayList<String> split(String source,
String seperator)
source - The string that will be split into parts.seperator - The seperator string that will be used to determine
the parts.
ArrayList containing the parts as
String objects.
public static ArrayList<String> split(String source,
String seperator,
boolean matchCase)
source - The string that will be split into parts.seperator - The seperator string that will be used to determine
the parts.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
ArrayList containing the parts as
String objects.
public static String[] splitToArray(String source,
String seperator)
source - The string that will be split into parts.seperator - The seperator string that will be used to determine
the parts.
String[] array containing the seperated parts.
public static String[] splitToArray(String source,
String seperator,
boolean matchCase)
source - The string that will be split into parts.seperator - The seperator string that will be used to determine
the parts.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
String[] array containing the seperated parts.
public static int[] splitToIntArray(String source,
String seperator)
source - The string that will be split into integers.seperator - The seperator string that will be used to determine
the parts.
int[] array containing the seperated parts.
public static int[] splitToIntArray(String source,
String seperator,
boolean matchCase)
source - The string that will be split into integers.seperator - The seperator string that will be used to determine
the parts.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
int[] array containing the seperated parts.
public static byte[] splitToByteArray(String source,
String seperator)
byte, it will be omitted from the resulting
array.
source - The string that will be split into bytes.seperator - The seperator string that will be used to determine
the parts.
byte[] array containing the bytes.
public static byte[] splitToByteArray(String source,
String seperator,
boolean matchCase)
byte, it will be omitted from the resulting array.
source - The string that will be split into bytes.seperator - The seperator string that will be used to determine
the parts.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
byte[] array containing the bytes.
public static String stripFromFront(String source,
String stringToStrip)
source - The string in which the matching will be done.stringToStrip - The string that will be stripped from the front.
String containing the stripped result.
public static String stripFromFront(String source,
String stringToStrip,
boolean matchCase)
source - The string in which the matching will be done.stringToStrip - The string that will be stripped from the front.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
String containing the stripping result.
public static String stripFromEnd(String source,
String stringToStrip)
source - The string in which the matching will be done.stringToStrip - The string that will be stripped from the end.
String containing the stripped result.
public static String stripFromEnd(String source,
String stringToStrip,
boolean matchCase)
source - The string in which the matching will be done.stringToStrip - The string that will be stripped from the end.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
String containing the stripped result.
public static String replace(String source,
String stringToReplace,
String replacementString)
source - The string in which the matching parts will be replaced.stringToReplace - The string that will be searched for.replacementString - The string that will replace each matching
part.
String object containing the replacement
result.
public static String replace(String source,
String stringToReplace,
String replacementString,
boolean matchCase)
source - The string in which the matching parts will be replaced.stringToReplace - The string that will be searched for.replacementString - The string that will replace each matching
part.matchCase - A boolean indicating if the match is
going to be performed in a case-sensitive manner or not.
String object containing the replacement
result.
public static String repeat(String source,
int count)
source - The string that will be repeated.count - The number of times that the string will be repeated.
String object containing the repeated
concatenation result.public static String[] toStringArray(Iterator<String> iterator)
String objects, containing the
elements of a supplied Iterator.
iterator - The iterator containing the elements to create the
array with.
String array.public static ArrayList<String> toArrayList(String[] stringArray)
ArrayList, containing the elements of a
supplied array of String objects.
stringArray - The array of String objects that have
to be converted.
ArrayList with the elements of the
String array.
public static String join(Collection collection,
String seperator)
String object, containing the elements of a
supplied Collection of String objects joined
by a given seperator.
collection - The Collection containing the elements
to join.seperator - The seperator used to join the string elements.
String with the join result.
public static String join(Object[] array,
String seperator)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The object array containing the elements to join.seperator - The seperator used to join the string elements.
String with the join result.
public static String join(Object[] array,
String seperator,
String delimiter)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The object array containing the elements to join.seperator - The seperator used to join the string elements.delimiter - The delimiter used to surround the string elements.
String with the join result.
public static String join(Object[] array,
String seperator,
String delimiter,
boolean encodeStrings)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The object array containing the elements to join.seperator - The seperator used to join the string elements.delimiter - The delimiter used to surround the string elements.encodeStrings - Indicates whether the characters of the string
representation of the Array values should be encoded.
String with the join result.
public static String join(boolean[] array,
String seperator)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The boolean array containing the values to join.seperator - The seperator used to join the string elements.
String with the join result.
public static String join(byte[] array,
String seperator)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The byte array containing the values to join.seperator - The seperator used to join the string elements.
String with the join result.
public static String join(double[] array,
String seperator)
String object, containing the elements of a
supplied array, joined by a given seperator.
array - The double array containing the values to join.seperator - The seperator used to join the string elements.
String with the join result.
public static String join(float[] array,