|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.unidata.util.StringUtil
public class StringUtil
String utilities
| Field Summary | |
|---|---|
static boolean |
debug
debug flag |
static String[] |
ordinalNames
Ordinal names for images |
| Constructor Summary | |
|---|---|
StringUtil()
|
|
| Method Summary | |
|---|---|
static String |
allow(String x,
String allowChars,
char replaceChar)
Replace any char not alphanumeric or in allowChars by replaceChar. |
static StringBuffer |
append(StringBuffer sb,
Object s1)
A utility method to an append to a StringBuffer. |
static StringBuffer |
append(StringBuffer sb,
Object s1,
Object s2)
A utility method to do multiple appends to a StringBuffer. |
static StringBuffer |
append(StringBuffer sb,
Object s1,
Object s2,
Object s3)
A utility method to do multiple appends to a StringBuffer. |
static StringBuffer |
append(StringBuffer sb,
Object s1,
Object s2,
Object s3,
Object s4)
A utility method to do multiple appends to a StringBuffer. |
static StringBuffer |
append(StringBuffer sb,
Object s1,
Object s2,
Object s3,
Object s4,
Object s5)
A utility method to do multiple appends to a StringBuffer. |
static String |
applyMacros(String s,
Hashtable props,
boolean throwError)
This takes a string of the following form. |
static String |
breakText(String text,
String insert,
int lineSize)
Convert the given text to html by adding <br>. |
static String |
breakTextAtWords(String text,
String insert,
int lineSize)
Break the given text into lines, respecting word boundaries (blank space). |
static String |
collapseWhitespace(String s)
Collapse continuous whitespace into one single " ". |
static boolean |
containsRegExp(String patternString)
See if a pattern string contains regular expression characters (^,*,$,+). |
static String |
escape(String x,
String okChars)
Escape any char not alphanumeric or in okChars. |
static String |
escape2(String x,
String reservedChars)
Escape any char in reservedChars. |
static List |
expandIso8601(String time)
A first attempt at parsing a dttm range string |
static String |
filter(String x,
String okChars)
Remove any char not alphanumeric or in okChars. |
static String |
filter7bits(String s)
Remove all but printable 7bit ascii |
static String |
findFormatString(String macroName,
String macroDelimiter,
String text)
Return the format string in the given text for the given macro. |
static Object |
findMatch(String source,
List patternList,
List results,
Object dflt)
Run through the List of patterns (pattern, result) and return corresponding result whose pattern matches the source string. |
static Object |
findMatch(String source,
List patternList,
Object dflt)
Run through the List of Objects and return the Object whose toString matches the source string. |
static String |
findPattern(String source,
String patternString)
Find the pattern in a string |
static String |
getAnOrA(String subject)
Get "a" or "an" for prefixing to a string based on the first character |
static boolean |
isDigits(String s)
Return true if all characters are numeric. |
static String |
join(String[] args)
Merge the given strings, using a space between each. |
static String |
join(String delimiter,
List args)
Merge the given strings, using the given delimiter between each. |
static String |
join(String delimiter,
List args,
boolean ignoreEmptyStrings)
Merge the given strings, using the given delimiter between each. |
static String |
join(String delimiter,
Object[] args)
Merge the given strings, using the given delimiter between each. |
static String |
join(String delimiter,
Object[] args,
boolean ignoreEmptyStrings)
Merge the given strings, using the given delimiter between each. |
static String |
listToString(List l)
Take the List of objects and return a String of all the list's elements toString values appended to each other, separated by semicolons |
static String[] |
listToStringArray(List objectList)
Take the List of objects and return a String array of the toString values of each object in the list. |
static void |
main(String[] args)
Method for debugging. |
static void |
main2(String[] args)
test |
static void |
main3(String[] args)
test |
static int |
match(String s1,
String s2)
Count number of chars that match in two strings, starting from front. |
static boolean |
notEmpty(String s)
|
static String |
padLeft(String s,
int desiredLength)
Pad the given string with spaces on the left up to the given length. |
static String |
padLeft(String s,
int desiredLength,
String padString)
Pad the given string with padString on the left up to the given length. |
static String |
padRight(String s,
int desiredLength)
Pad the given string with spaces on the right up to the given length. |
static String |
padRight(String s,
int desiredLength,
String padString)
Pad the given string with padString on the right up to the given length. |
static String |
padZero(int value,
int numDigits)
Left pad the given value with zeros up to the number of digits |
static double[][] |
parseCoordinates(String coords)
Parse the lat/lon/alt coordinate string |
static List |
parseCsv(String s,
boolean skipFirst)
Parse a comma separated value (CVS) String |
static Date |
parseDate(String dttm)
Parse the date. |
static List |
parseIntegerListString(String s)
Parse the given string and return a list of Integer values. |
static Date |
parseIso8601(String time)
Not working yet but this is supposed to parse an iso8601 date format |
static List |
parseLineWords(String content,
int[] indices,
int[] lengths,
String lineDelimiter,
String commentString,
boolean trimWords)
This splits the given content String into a set of lines (delimited by the given lineDelimiter). |
static Hashtable |
parsePropertiesString(String s)
Parse the semi-colon delimited string of name=value properties. |
static long |
parseTimePeriod(String s)
Note, right now this just parses the hour/minute/second periods |
static String |
quoteHtmlContent(String x)
Replace special characters with entities for HTML content. |
static String |
quoteXmlAttribute(String x)
Replace special characters with entities for XML attributes. |
static String |
quoteXmlContent(String x)
Replace special characters with entities for XML attributes. |
static String |
remove(String s,
int c)
Remove all occurrences of the character c in the string s. |
static String |
remove(String s,
String sub)
Remove all occurrences of the substring sub in the string s. |
static String |
removeWhitespace(String inputString)
Remove any whitespace (ie., Character.isWhitespace) from the input string. |
static String |
repeat(String s,
int cnt)
Concatentate the given string cnt times |
static void |
replace(StringBuffer sb,
char out,
String in)
Replace any char "out" in sb with "in". |
static String |
replace(String s,
char out,
String in)
Replace any char "out" in s with "in". |
static String |
replace(String string,
String pattern,
String value)
Replaces all occurrences of "pattern" in "string" with "value" |
static List |
replaceList(List sourceList,
String[] patterns,
String[] values)
Construct and return a list of Strings where each string is the result of replacing all of the patterns with the corresponding values for each String in the given sourceList . |
static String |
replaceList(String v,
List patterns,
List values)
Replaces all occurrences of "patterns" in "v" with "values" |
static String |
replaceList(String v,
String[] patterns,
String[] values)
Replaces all occurrences of "patterns" in "v" with "values" |
static String |
shorten(String s,
int length)
Shorten a string using elipses (...) |
static List<String> |
split(Object source)
Tokenize the toString value of the given source object, splitting on ",". |
static List<String> |
split(Object source,
String delimiter)
Tokenize the toString value of the given source object, splitting on the given delimiter. |
static List<String> |
split(Object source,
String delimiter,
boolean trim)
Tokenize the toString value of the given source object, splitting on the given delimiter. |
static List<String> |
split(Object source,
String delimiter,
boolean trim,
boolean excludeZeroLength)
Tokenize the toString value of the given source object, splitting on the given delimiter. |
static String[] |
split(String s,
String delimiter,
int cnt)
Split the given string into the first cnt number of substrings as delimited by the given delimiter. |
static List |
splitMacros(String s)
This parses the given string with the following form. |
static boolean |
startsWithVowel(String value)
Check to see if the string starts with a vowel. |
static boolean |
stringMatch(String input,
String patternString)
Check if the given input String matches the given pattern String. |
static boolean |
stringMatch(String input,
String patternString,
boolean substring,
boolean caseSensitive)
Check if the given input String matches the given pattern String. |
static String |
stripAndReplace(String s,
String pattern1,
String pattern2,
String replace)
Replaces all occurrences of the strings delimited by patter1/pattern2 with replace, e.g.: "pattern1 ... |
static String |
stripHtmlTag(String html)
Remove any beginning or ending <html> tags |
static String |
stripTags(String html)
Remove all text contained within "< >" tags. |
static void |
substitute(StringBuffer sbuff,
String match,
String subst)
Find all occurences of the "match" in original, and substitute the "subst" string, directly into the original. |
static String |
substitute(String original,
String[] match,
String[] subst)
Find all occurences of match strings in original, and substitute the corresponding subst string. |
static String |
substitute(String original,
String match,
String subst)
Find all occurences of the "match" in original, and substitute the "subst" string. |
static String |
toHexString(Color c)
Convert the given color to is string hex representation |
static List |
toString(List l)
Convert the list of objects to a list of strings. |
static String |
toString(Object[] array)
Create a string representation of the given array |
static String |
unescape(String x)
This finds any '%xx' and converts to the equivilent char. |
static String |
unquoteXmlAttribute(String x)
Reverse XML quoting to recover the original string. |
static String |
unquoteXmlContent(String x)
Reverse XML quoting to recover the original string. |
static void |
unreplace(StringBuffer sb,
String out,
char in)
Replace any String "out" in sb with char "in". |
static String |
zeroString(int value)
If the given value is less than 10 than pad the String return with a leading "0". |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static boolean debug
public static final String[] ordinalNames
| Constructor Detail |
|---|
public StringUtil()
| Method Detail |
|---|
public static boolean notEmpty(String s)
public static String collapseWhitespace(String s)
s - operate on this string
public static String remove(String s,
String sub)
s - operate on this stringsub - remove all occurrences of this substring.
public static String remove(String s,
int c)
s - operate on this stringc - remove all occurrences of this character.
public static String findFormatString(String macroName,
String macroDelimiter,
String text)
macroName - The name of the macromacroDelimiter - The delimiter used. e.g. '%'text - the text
public static String substitute(String original,
String match,
String subst)
original - starting stringmatch - string to matchsubst - string to substitute
public static String repeat(String s,
int cnt)
s - base stringcnt -
public static String substitute(String original,
String[] match,
String[] subst)
original - starting stringmatch - array of strings to matchsubst - array of strings to substitute
public static void substitute(StringBuffer sbuff,
String match,
String subst)
sbuff - starting string buffermatch - string to matchsubst - string to substitutepublic static boolean isDigits(String s)
s - operate on this String
public static String quoteHtmlContent(String x)
x - string to quote
public static String quoteXmlContent(String x)
x - string to quote
public static String unquoteXmlContent(String x)
x - string to quote
public static String quoteXmlAttribute(String x)
x - string to quote
public static String unquoteXmlAttribute(String x)
x - string to quote
public static int match(String s1,
String s2)
s1 - compare this strings2 - compare this string
public static void replace(StringBuffer sb,
char out,
String in)
sb - StringBuffer to replaceout - repalce this characterin - with this string
public static void unreplace(StringBuffer sb,
String out,
char in)
sb - StringBuffer to replaceout - repalce this Stringin - with this char
public static String replace(String s,
char out,
String in)
s - string to replaceout - repalce this characterin - with this string
public static String escape(String x,
String okChars)
x - escape this stringokChars - these are ok.
public static String escape2(String x,
String reservedChars)
x - escape this stringreservedChars - these must be replaced
public static String toHexString(Color c)
c - color
public static String filter7bits(String s)
s - filter this string
public static String filter(String x,
String okChars)
x - filter this stringokChars - these are ok.
public static String allow(String x,
String allowChars,
char replaceChar)
x - operate on this stringallowChars - these are ok.replaceChar - thar char to replace
public static String unescape(String x)
x -
public static Object findMatch(String source,
List patternList,
Object dflt)
source - Source String to match on.patternList - List of objects whose toString is the pattern.dflt - The default if nothing matches.
public static Object findMatch(String source,
List patternList,
List results,
Object dflt)
source - Source String to match on.patternList - List of objects whose toString is the pattern.results - The list of return objects.dflt - The default if nothing matches.
public static boolean containsRegExp(String patternString)
patternString - pattern string to check
public static boolean stringMatch(String input,
String patternString)
input - The input source string.patternString - The regular expression pattern.
public static boolean stringMatch(String input,
String patternString,
boolean substring,
boolean caseSensitive)
input - The input source string.patternString - The regular expression pattern.substring - Search for substringscaseSensitive - Is case sensitive
public static boolean startsWithVowel(String value)
value - String to check
public static String breakText(String text,
String insert,
int lineSize)
text - The text to convertinsert - string to insertlineSize - line size to insert at
public static String breakTextAtWords(String text,
String insert,
int lineSize)
text - The text to convertinsert - break to insertlineSize - line size to insert at
public static String stripHtmlTag(String html)
html - the html
public static String stripTags(String html)
html - The source html string.
public static String stripAndReplace(String s,
String pattern1,
String pattern2,
String replace)
s - initial stringpattern1 - delimiter 1pattern2 - delimiter 2replace - replace with
public static String removeWhitespace(String inputString)
inputString - The string to remove the whitespace.
public static String zeroString(int value)
value - The value.
public static String padZero(int value,
int numDigits)
value - The value.numDigits - number of digits
public static String padLeft(String s,
int desiredLength)
s - String to paddesiredLength - ending length
public static String padLeft(String s,
int desiredLength,
String padString)
s - String to paddesiredLength - ending lengthpadString - String to pad with (e.g, " ")
public static String padRight(String s,
int desiredLength)
s - String to paddesiredLength - ending length
public static String padRight(String s,
int desiredLength,
String padString)
s - String to paddesiredLength - ending lengthpadString - String to pad with (e.g, " ")
public static String join(String[] args)
args - An array of Strings to merge.
public static String join(String delimiter,
Object[] args)
delimiter - The delimiter.args - An array of Strings to merge.
public static String join(String delimiter,
Object[] args,
boolean ignoreEmptyStrings)
delimiter - The delimiter.args - An array of Strings to merge.ignoreEmptyStrings - Don't join empty strings
public static String join(String delimiter,
List args)
delimiter - The delimiter.args - A List of objects whose toString value are merged.
public static String join(String delimiter,
List args,
boolean ignoreEmptyStrings)
delimiter - The delimiter.args - A List of objects whose toString value are merged.ignoreEmptyStrings - Should ignore empty strings
public static List<String> split(Object source)
source - The source object string.
public static Date parseDate(String dttm)
yyyy-MM-dd HH:mm:ss z yyyy-MM-dd HH:mm:ss yyyy-MM-dd HH:mm yyyy-MM-dd yyyyMMddHHmmss yyyyMMddHHmm yyyyMMddHH yyyyMMdd
dttm - The date string
public static List parseIntegerListString(String s)
1,2,3 - the numbers 1 2 and 3 0:10,15:20,30 - 0-10, 15-20 and 30 0:10:2 - 0,2,4,6,8,10
s - The string to parse
public static List parseLineWords(String content,
int[] indices,
int[] lengths,
String lineDelimiter,
String commentString,
boolean trimWords)
content - The String to parseindices - the index in the line which defines the word start.lengths - the length of each word.lineDelimiter - What to split the line content string on (usually "\n").commentString - If non-null defines the comment String in the content.trimWords - Do we trim each word.
public static List<String> split(Object source,
String delimiter)
source - The source object string.delimiter - The delimiter to break up the sourceString on.
public static List<String> split(Object source,
String delimiter,
boolean trim)
source - The source object string.delimiter - The delimiter to break up the sourceString on.trim - Do we string trim the tokens.
public static List<String> split(Object source,
String delimiter,
boolean trim,
boolean excludeZeroLength)
source - The source object string.delimiter - The delimiter to break up the sourceString on.trim - Do we string trim the tokens.excludeZeroLength - If true then don't add in zero length strings.
public static String[] split(String s,
String delimiter,
int cnt)
s - String to splitdelimiter - token delimetercnt - max number of tokens
null if unable to split
the string.public static String[] listToStringArray(List objectList)
objectList - The list of objects.
public static String listToString(List l)
l - list of objects
public static List toString(List l)
l - List of objects
public static String replace(String string,
String pattern,
String value)
string - string to mungepattern - pattern to replacevalue - replacement value
public static String replaceList(String v,
String[] patterns,
String[] values)
v - original Stringpatterns - patterns to matchvalues - replacement values
public static String replaceList(String v,
List patterns,
List values)
v - original Stringpatterns - patterns to matchvalues - replacement values
public static List replaceList(List sourceList,
String[] patterns,
String[] values)
sourceList - original list of Stringspatterns - patterns to replacevalues - replacement values
public static StringBuffer append(StringBuffer sb,
Object s1)
sb - StringBuffer to append to (may be null)s1 - object to append