|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.StringUtils
Stringtils is a class for random String things.
Method Summary | |
static Map |
argsToMap(String[] args)
Parses command line arguments into a Map. |
static Map |
argsToMap(String[] args,
Map flagsToNumArgs)
Parses command line arguments into a Map. |
static Properties |
argsToProperties(String[] args)
|
static Properties |
argsToProperties(String[] args,
Map flagsToNumArgs)
Analagous to argsToMap(java.lang.String[]) . |
static String |
exactlyN(Object obj,
int totalChars)
Pad or trim the toString value of the given Object. |
static String |
exactlyN(String inStr,
int num)
Pad or trim so as to produce a string of exactly a certain length. |
static String |
fileNameClean(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(String str,
String regex)
Say whether this regular expression can be found inside this String. |
static String |
join(List l)
Joins elems with a space. |
static String |
join(List l,
String glue)
Joins each elem in the List with the given glue. |
static String |
join(Object[] elements)
Joins elems with a space. |
static String |
join(Object[] elements,
String glue)
Joins each elem in the array with the given glue. |
static String |
leftPad(double d,
int totalChars)
|
static String |
leftPad(int i,
int totalChars)
|
static String |
leftPad(Object obj,
int totalChars)
|
static String |
leftPad(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(String str,
String regex)
Say whether this regular expression can be found at the beginning of this String. |
static boolean |
matches(String str,
String regex)
Say whether this regular expression matches this String. |
static int |
nthIndex(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 String |
pad(Object obj,
int totalChars)
Pads the toString value of the given Object. |
static String |
pad(String str,
int totalChars)
Return a String of length a minimum of totalChars characters by padding the input String str with spaces. |
static String |
paddedIntToString(int n,
int smallestDigit,
int biggestDigit)
This returns a string from decimal digit smallestDigit to decimal digit biggest digit. |
static Map |
parseCommandLineArguments(String[] args)
THIS IS HIGHLY SUPERIOR TO THE OVERLY COMPLEXIFIED CODE THAT COMES BEFORE IT. |
static void |
printToFile(String filename,
String message)
Prints to a file. |
static void |
printToFile(String filename,
String message,
boolean append)
Prints to a file. |
static String |
slurpFile(File file)
Returns all the text in the given File. |
static String |
slurpFile(String filename)
Returns all the text in the given File. |
static String |
slurpURL(URL u)
Returns all the text at the given URL. |
static List |
split(String s)
Splits on whitespace (\\s+). |
static List |
split(String str,
String regex)
Splits the given string using the given regex as delimiters. |
static String |
trim(Object obj,
int maxWidth)
|
static String |
trim(String s,
int maxWidth)
Returns s if it's at most maxWidth chars, otherwise chops right side to fit. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static boolean find(String str, String regex)
str
- String to search for match inregex
- String to compile as the regular expression
public static boolean lookingAt(String str, String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expression
public static boolean matches(String str, String regex)
str
- String to search for match at start ofregex
- String to compile as the regular expression
public static String slurpFile(File file) throws IOException
IOException
public static String slurpFile(String filename)
public static String slurpURL(URL u) throws IOException
IOException
public static String join(List l, String glue)
public static String join(Object[] elements, String glue)
public static String join(List l)
public static String join(Object[] elements)
public static List split(String s)
public static List split(String str, String regex)
str
- String to split upregex
- String to compile as the regular expression
public static String pad(String str, int totalChars)
public static String pad(Object obj, int totalChars)
public static String exactlyN(String inStr, int num)
inStr
- The String to be padded or truncatednum
- The desired lengthpublic static String exactlyN(Object obj, int totalChars)
public static String leftPad(String str, int totalChars)
public static String leftPad(Object obj, int totalChars)
public static String leftPad(int i, int totalChars)
public static String leftPad(double d, int totalChars)
public static String trim(String s, int maxWidth)
public static String trim(Object obj, int maxWidth)
public static String fileNameClean(String s)
public static int nthIndex(String s, char ch, int n)
public static String paddedIntToString(int n, int smallestDigit, int biggestDigit)
public static Map argsToMap(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 Map argsToMap(String[] args, Map 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 = parseCommandLineArguments(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 Properties argsToProperties(String[] args)
public static Properties argsToProperties(String[] args, Map flagsToNumArgs)
argsToMap(java.lang.String[])
. However, there are several key differences between this method and argsToMap(java.lang.String[])
:
public static void printToFile(String filename, String message, boolean append)
append=true
, and overwrites if append=false
public static void printToFile(String filename, String message)
public static Map parseCommandLineArguments(String[] args)
args
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |