|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.StringUtils
public class StringUtils
StringUtils is a class for random String things.
Method Summary | |
---|---|
static java.util.Map<java.lang.String,java.lang.String[]> |
argsToMap(java.lang.String[] args)
Parses command line arguments into a Map. |
static java.util.Map<java.lang.String,java.lang.String[]> |
argsToMap(java.lang.String[] args,
java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
Parses command line arguments into a Map. |
static java.util.Properties |
argsToProperties(java.lang.String[] args)
|
static java.util.Properties |
argsToProperties(java.lang.String[] args,
java.util.Map flagsToNumArgs)
Analagous to argsToMap(java.lang.String[]) . |
static java.lang.String |
escapeString(java.lang.String s,
char[] charsToEscape,
char escapeChar)
|
static java.lang.String |
escapeStringForXML(java.lang.String s)
|
static java.lang.String |
escapeTextAroundXMLTags(java.lang.String s)
|
static java.lang.String |
exactlyN(java.lang.Object obj,
int totalChars)
Pad or trim the toString value of the given Object. |
static java.lang.String |
exactlyN(java.lang.String inStr,
int num)
Pad or trim so as to produce a string of exactly a certain length. |
static java.lang.String |
fileNameClean(java.lang.String s)
Returns a "clean" version of the given filename in which spaces have been converted to dashes and all non-alphaneumeric chars are underscores. |
static boolean |
find(java.lang.String str,
java.lang.String regex)
Say whether this regular expression can be found inside this String. |
static java.lang.String |
join(java.lang.Iterable l,
java.lang.String glue)
Joins each elem in the Collection with the given glue. |
static java.lang.String |
join(java.util.List l)
Joins elems with a space. |
static java.lang.String |
join(java.util.List l,
java.lang.String glue)
Joins each elem in the List with the given glue. |
static java.lang.String |
join(java.lang.Object[] elements)
Joins elems with a space. |
static java.lang.String |
join(java.lang.Object[] elements,
java.lang.String glue)
Joins each elem in the array with the given glue. |
static java.lang.String |
leftPad(double d,
int totalChars)
|
static java.lang.String |
leftPad(int i,
int totalChars)
|
static java.lang.String |
leftPad(java.lang.Object obj,
int totalChars)
|
static java.lang.String |
leftPad(java.lang.String str,
int totalChars)
Pads the given String to the left with spaces to ensure that it's at least totalChars long. |
static boolean |
lookingAt(java.lang.String str,
java.lang.String regex)
Say whether this regular expression can be found at the beginning of this String. |
static void |
main(java.lang.String[] args)
|
static boolean |
matches(java.lang.String str,
java.lang.String regex)
Say whether this regular expression matches this String. |
static int |
nthIndex(java.lang.String s,
char ch,
int n)
Returns the index of the nth occurrence of ch in s, or -1 if there are less than n occurrences of ch. |
static java.lang.String |
pad(java.lang.Object obj,
int totalChars)
Pads the toString value of the given Object. |
static java.lang.String |
pad(java.lang.String str,
int totalChars)
Return a String of length a minimum of totalChars characters by padding the input String str with spaces. |
static java.util.Map |
parseCommandLineArguments(java.lang.String[] args)
A simpler form of command line argument parsing. |
static void |
printStringOneCharPerLine(java.lang.String s)
|
static void |
printToFile(java.io.File file,
java.lang.String message)
Prints to a file. |
static void |
printToFile(java.io.File file,
java.lang.String message,
boolean append)
Prints to a file. |
static void |
printToFile(java.lang.String filename,
java.lang.String message)
Prints to a file. |
static void |
printToFile(java.lang.String filename,
java.lang.String message,
boolean append)
Prints to a file. |
static java.lang.String |
slurpFile(java.io.File file)
Returns all the text in the given File. |
static java.lang.String |
slurpFile(java.lang.String filename)
Returns all the text in the given File. |
static java.lang.String |
slurpFileNoExceptions(java.io.File file)
Returns all the text in the given File. |
static java.lang.String |
slurpFileNoExceptions(java.lang.String filename)
Returns all the text in the given File. |
static java.lang.String |
slurpURL(java.net.URL u)
Returns all the text at the given URL. |
static java.lang.String |
slurpURLNoExceptions(java.net.URL u)
Returns all the text at the given URL. |
static java.util.List |
split(java.lang.String s)
Splits on whitespace (\\s+). |
static java.util.List |
split(java.lang.String str,
java.lang.String regex)
Splits the given string using the given regex as delimiters. |
static java.lang.String[] |
splitOnCharWithQuoting(java.lang.String s,
char splitChar,
char quoteChar,
char escapeChar)
This function splits the String s into multiple Strings using the splitChar. |
static java.util.Properties |
stringToProperties(java.lang.String str)
This method converts a comma-separated String (with whitespace optionally allowed after the comma) representing properties to a Properties object. |
static java.lang.String |
trim(java.lang.Object obj,
int maxWidth)
|
static java.lang.String |
trim(java.lang.String s,
int maxWidth)
Returns s if it's at most maxWidth chars, otherwise chops right side to fit. |
static java.lang.String |
truncate(int n,
int smallestDigit,
int biggestDigit)
This returns a string from decimal digit smallestDigit to decimal digit biggest digit. |
static java.lang.String |
unescapeStringForXML(java.lang.String s)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean find(java.lang.String str, java.lang.String regex)
str
- String to search for match inregex
- String to compile as the regular expression
public static boolean lookingAt(java.lang.String str, java.lang.String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expression
public static boolean matches(java.lang.String str, java.lang.String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expression
public static java.lang.String slurpFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpFile(java.lang.String filename) throws java.io.IOException
null
.
java.io.IOException
public static java.lang.String slurpFileNoExceptions(java.io.File file)
public static java.lang.String slurpFileNoExceptions(java.lang.String filename)
null
.public static java.lang.String slurpURL(java.net.URL u) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpURLNoExceptions(java.net.URL u)
public static java.lang.String join(java.lang.Iterable l, java.lang.String glue)
public static java.lang.String join(java.util.List l, java.lang.String glue)
public static java.lang.String join(java.lang.Object[] elements, java.lang.String glue)
public static java.lang.String join(java.util.List l)
public static java.lang.String join(java.lang.Object[] elements)
public static java.util.List split(java.lang.String s)
public static java.util.List split(java.lang.String str, java.lang.String regex)
str
- String to split upregex
- String to compile as the regular expression
public static java.lang.String pad(java.lang.String str, int totalChars)
public static java.lang.String pad(java.lang.Object obj, int totalChars)
public static java.lang.String exactlyN(java.lang.String inStr, int num)
inStr
- The String to be padded or truncatednum
- The desired lengthpublic static java.lang.String exactlyN(java.lang.Object obj, int totalChars)
public static java.lang.String leftPad(java.lang.String str, int totalChars)
public static java.lang.String leftPad(java.lang.Object obj, int totalChars)
public static java.lang.String leftPad(int i, int totalChars)
public static java.lang.String leftPad(double d, int totalChars)
public static java.lang.String trim(java.lang.String s, int maxWidth)
public static java.lang.String trim(java.lang.Object obj, int maxWidth)
public static java.lang.String fileNameClean(java.lang.String s)
public static int nthIndex(java.lang.String s, char ch, int n)
public static java.lang.String truncate(int n, int smallestDigit, int biggestDigit)
public static java.util.Map<java.lang.String,java.lang.String[]> argsToMap(java.lang.String[] args)
String[]
containing
the optional arguments (if present). The non-flag values not
captured as flag arguments are collected into a String[] array
and returned as the value of null
in the Map. In
this invocation, flags cannot take arguments, so all the String
array values other than the value for null
will be zero-length.
args
-
Map
of flag names to flag argument String[]
arrays.public static java.util.Map<java.lang.String,java.lang.String[]> argsToMap(java.lang.String[] args, java.util.Map<java.lang.String,java.lang.Integer> flagsToNumArgs)
String[]
containing
the optional arguments (if present). The non-flag values not
captured as flag arguments are collected into a String[] array
and returned as the value of null
in the Map. In
this invocation, the maximum number of arguments for each flag
can be specified as an Integer
value of the appropriate
flag key in the flagsToNumArgs
Map
argument. (By default, flags cannot take arguments.)
Example of usage:
Map flagsToNumArgs = new HashMap();
flagsToNumArgs.put("-x",new Integer(2));
flagsToNumArgs.put("-d",new Integer(1));
Map result = argsToMap(args,flagsToNumArgs);
args
- the argument array to be parsedflagsToNumArgs
- a Map
of flag names to Integer
values specifying the maximum number of allowed
arguments for that flag (default 0).
Map
of flag names to flag argument String[]
arrays.public static java.util.Properties argsToProperties(java.lang.String[] args)
public static java.util.Properties argsToProperties(java.lang.String[] args, java.util.Map flagsToNumArgs)
argsToMap(java.lang.String[])
. However, there are several key differences between this method and argsToMap(java.lang.String[])
:
public static java.util.Properties stringToProperties(java.lang.String str)
public static void printToFile(java.io.File file, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
public static void printToFile(java.io.File file, java.lang.String message)
public static void printToFile(java.lang.String filename, java.lang.String message, boolean append)
append=true
, and overwrites if append=false
public static void printToFile(java.lang.String filename, java.lang.String message)
public static java.util.Map parseCommandLineArguments(java.lang.String[] args)
args
-
public static void printStringOneCharPerLine(java.lang.String s)
public static java.lang.String unescapeStringForXML(java.lang.String s)
public static java.lang.String escapeStringForXML(java.lang.String s)
public static java.lang.String escapeTextAroundXMLTags(java.lang.String s)
public static java.lang.String escapeString(java.lang.String s, char[] charsToEscape, char escapeChar)
public static java.lang.String[] splitOnCharWithQuoting(java.lang.String s, char splitChar, char quoteChar, char escapeChar)
s
- The String to splitsplitChar
- quoteChar
-
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |