|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.umd.cfar.lamp.viper.util.StringHelp
This class contains generic static string manipulation and generation functions.
Field Summary | |
static int |
REL_EQ
Equality relation |
static int |
REL_GT
Greater than relation |
static int |
REL_GTEQ
Greater than or equals relation |
static int |
REL_LT
Less than relation |
static int |
REL_LTEQ
Less than or equals relation |
static int |
REL_NEQ
Inequality relation |
Constructor Summary | |
StringHelp()
|
Method Summary | |
static java.lang.String |
backslashify(java.lang.String str)
Converts special characters to escpe key sequences. |
static java.lang.String |
banner(java.lang.String text,
int width)
Generates an asterisk-surrounded banner containing the given text. |
static boolean |
containsCommaSeparatedList(java.lang.String s)
Checks if there are commas that aren't within quote marks. |
static java.util.Iterator |
debackslashedTokenizer(java.lang.String str)
Tokenizes like the bash command line. |
static java.lang.String |
debackslashify(java.lang.String str)
Converts escape sequences to their real characters, like new lines. |
static java.lang.String |
encodeAsAnAcceptableFileName(java.lang.String s)
Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. |
static java.lang.String |
getExtraTextOutsideBrackets(java.lang.String line)
Get the characters from a bracketed list that are not in brackets. |
static java.util.List |
getQuotedList(java.lang.String str)
Converts a comma seperated list of quoted strings to a list of debackslashified strings. |
static java.lang.String |
getQuotedListString(java.util.List list)
Returns the list as a comma sepatated list of quoted and escaped strings. |
static int |
getRelationalOperatorEnum(java.lang.String rel_op)
Converts the string, e.g. |
static java.lang.String |
getRelationalOperatorString(int rel_op_enum)
Gets the string for the relational operator. |
static void |
handleExtraTextOutsideBrackets(java.lang.String line,
ErrorWriter err)
Prints a warning for test that should all be inside brackets but has some outside. |
static int |
hasUnmatchedBrackets(java.lang.String str)
Checks to see if the String has marching '[' and ']' characters. |
static boolean |
isLegalIdentifier(java.lang.String str)
Checks to see if a String is a legal identifier. |
static boolean |
isLogicalOperator(java.lang.String log_op)
Will return true if the string passed to it is one of the defined logical operators. |
static boolean |
isRelationalOperator(java.lang.String rel_op)
Will return true if the string passed to it is one of the defined relational operators. |
static boolean |
isXMLFormat(java.io.File f)
Checks to see if the file begins with an xml processing directive, eg <? |
static boolean |
isXMLFormat(java.io.InputStream f)
Checks to see if the stream begins with an xml processing directive, eg <? |
static boolean |
isXMLFormat(java.lang.String fileName)
Checks to see if the file begins with an xml processing directive, eg <? |
static boolean |
isXMLFormat(java.lang.String configFileName,
java.lang.String dataFileName)
Determines by file content if the data is in XML format. |
static java.lang.String |
padLeft(int amount,
java.lang.String S)
This function returns a string equal to amount
number of ' ' characters added to the front of the string
S . |
static java.lang.String |
removeSpacesFrom(java.lang.String candidate)
Will remove whitespace chars from the string. |
static java.lang.String |
shorten(java.lang.String line)
Removes the first and last character of the string. |
static java.lang.String[] |
splitByBrackets(java.lang.String line)
Extracts a list of all strings contained within brackets. |
static java.lang.String[] |
splitByCommas(java.lang.String line)
Deprecated. If you must, use this line: splitBySeparator (removeBrackets (line), ",") |
static java.lang.String[] |
splitBySeparator(java.lang.String line,
char sep)
Split using a seperator. |
static java.lang.String[] |
splitBySeparatorAndParen(java.lang.String line,
char sep)
Split using a separator, but allow for the separator to occur in nested parentheses without splitting. |
static java.lang.String[] |
splitBySeparatorQuoteAndParen(java.lang.String line,
char sep)
Split using a separator, but allow for the separator to occur in nested parentheses without splitting. |
static java.lang.String[] |
splitSpaces(java.lang.String line)
Divides a String by its whitespace. |
static java.lang.String |
underliner(boolean starts,
boolean ends,
int start,
int end)
This is useful for generating jikes-style underlines for compiler errors and warnings. |
static java.lang.String |
unescapeAnAcceptableFileName(java.lang.String s)
Decodes a string encoded with encodeAsAnAcceptableFileName(String) ,
which is to say it decodes any URL encoded string. |
static java.lang.String |
webify(java.lang.String str)
Convert the plain text string into something that is a valid HTML/XML text string (i.e. escaping angle brackets, etc.). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int REL_EQ
public static final int REL_LT
public static final int REL_GT
public static final int REL_LTEQ
public static final int REL_GTEQ
public static final int REL_NEQ
Constructor Detail |
public StringHelp()
Method Detail |
public static java.lang.String underliner(boolean starts, boolean ends, int start, int end)
i += foo; <->The first two arguments allow for multiline underlines. eg:
<----------------------------------------- i = ((Descriptor) vec.elementAt (g).sameTypeAs (other); ------^
starts
- Does the thing to be underlined start on this line?ends
- Does it end on this line?start
- The character offset of the first offending mark on this lineend
- The last character in the error on this line.
public static java.lang.String padLeft(int amount, java.lang.String S)
amount
number of ' ' characters added to the front of the string
S
.
amount
- Number of spaces to pad.S
- The string that requires padding.
amount
+ S
public static java.lang.String[] splitSpaces(java.lang.String line)
line
- The String to divide.
public static java.lang.String shorten(java.lang.String line)
line
- The String to be shortened
public static java.lang.String getExtraTextOutsideBrackets(java.lang.String line)
... [ foo ] ... [1.2 1.2] ... [hi] ...If there isn't anything outside the brackets, it returns null.
line
- The String to check.
null
if there
is no such text.public static void handleExtraTextOutsideBrackets(java.lang.String line, ErrorWriter err)
warning
.
line
- The line that might have a problem.err
- The ErrorWriter that gets the warning, if there is one.splitByBrackets(String line)
public static java.lang.String[] splitByBrackets(java.lang.String line)
[ foo ] [1.2 1.2] [hi]This will return {" foo ", "1.2 1.2", "hi"}.
line
- The data to be split.
java.lang.IllegalArgumentException
- if brackets are unbalancedpublic static int hasUnmatchedBrackets(java.lang.String str)
str
- The String in which to check the brackets.
0
: Brackets match up.-1
: Too many left brackets.1
: Missing right bracketspublic static java.lang.String[] splitByCommas(java.lang.String line)
splitBySeparator (removeBrackets (line), ",")
line
- A String of the format (alpha, beta, gamma)
public static java.lang.String[] splitBySeparator(java.lang.String line, char sep)
line
- The String to be seperated.sep
- The seperator character, eg a comma
splitBySeparatorAndParen(String line, char sep)
public static java.lang.String[] splitBySeparatorAndParen(java.lang.String line, char sep)
1, (2,3), 4would split into
line
- The String to be seperated.sep
- The seperator character, eg a comma
splitBySeparator(String line, char c)
public static java.lang.String[] splitBySeparatorQuoteAndParen(java.lang.String line, char sep)
E.g. "1", 2*("2,3"), "4" would split into -- "1" -- 2*("2,3") -- "4"If the data has an odd number of "s, it will append a " character to the end. In order to include a quote character without delimiting a string, use the \". For a \, use \\.
line
- the string to splitsep
- the seperator character, e.g. a comma
public static boolean isLegalIdentifier(java.lang.String str)
str
- The String to check.
true
if the String uses valid characters.public static boolean containsCommaSeparatedList(java.lang.String s)
HELLO, THERE, FINEBut the following isn't
"hello, world" "fine, thank you"since the commas are between quotes. Note: This doesn't do checking for control characters, so it won't work on data that contains them, eg.
"Say \"Hello,\" World."
s
- The String to check.
true
if this looks like a comma seperated list.public static boolean isRelationalOperator(java.lang.String rel_op)
<
,
>
, <=
, >=
,
==
, and !=
.
rel_op
- the string that has to be tested if it is a rel op
public static int getRelationalOperatorEnum(java.lang.String rel_op)
==or
<=, to the constant.
rel_op
- the relational operator
REL_EQ
public static java.lang.String getRelationalOperatorString(int rel_op_enum)
rel_op_enum
- the constant int for the operator
public static boolean isLogicalOperator(java.lang.String log_op)
&&
and ||
.
log_op
- the string that has to be tested if it is a log op
public static java.lang.String removeSpacesFrom(java.lang.String candidate)
candidate
- String with whitespace characters.
public static java.lang.String backslashify(java.lang.String str)
\n
.
str
- The string containing control characters that
should be expanded
debackslashify(String str)
public static java.util.Iterator debackslashedTokenizer(java.lang.String str)
str
- the string to tokenize
public static java.lang.String getQuotedListString(java.util.List list)
list
- the list to print as a string
public static java.util.List getQuotedList(java.lang.String str) throws BadDataException
"one", "two", "three"
will
convert to a list containing three strings, each
stripped of quotes.
str
- The string containing a list.
BadDataException
debackslashify(String str)
public static java.lang.String debackslashify(java.lang.String str) throws java.lang.IllegalArgumentException
I went to \"http:\\\\java.sun.com\\\",\nbut they didn't sell coffee.becomes:
I went to "http:\\java.sun.com\", but they didn't sell coffee.
str
- The string containing C-style control characters.
java.lang.IllegalArgumentException
- if the last character is a
backslash (e.g. "some\"
)backslashify(String str)
public static java.lang.String webify(java.lang.String str)
str
- the string to escape
public static java.lang.String banner(java.lang.String text, int width)
banner("Hello, world!",12)
generates:
*********** * Hello, * * world! * ***********
text
- width
-
public static boolean isXMLFormat(java.lang.String configFileName, java.lang.String dataFileName) throws java.io.IOException
configFileName
- The config file name. XML files only
have the data file, so if this is not null, this
method returns false.dataFileName
- The name of the data file, the file that
is checked for the processing directive
java.io.IOException
- if there was a problem with the data file.public static boolean isXMLFormat(java.lang.String fileName) throws java.io.IOException
<?xml?>
. This method does not check to see that the
file is well-formed, or even if the processing directive is good, just that
the first non-whitespace characters are "<?xml".
fileName
- The file to check for xml processing directive
true
if the directive was found.
java.io.IOException
- if there is an error while reading the file, eg FileNotFoundExceptionpublic static boolean isXMLFormat(java.io.File f) throws java.io.IOException
<?xml?>
. This method does not check to see that the
file is well-formed, or even if the processing directive is good, just that
the first non-whitespace characters are "<?xml".
f
- The file to check for xml processing directive
true
if the directive was found.
java.io.IOException
- if there is an error while reading the file, eg FileNotFoundExceptionpublic static boolean isXMLFormat(java.io.InputStream f) throws java.io.IOException
<?xml?>
. This method does not check to see that the
stream is well-formed, or even if the processing directive is good, just that
the first non-whitespace characters are "<?xml".
f
- The file to check for xml processing directive
true
if the directive was found.
java.io.IOException
- if there is an error while reading the file, eg FileNotFoundExceptionpublic static java.lang.String encodeAsAnAcceptableFileName(java.lang.String s)
The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.
The unreserved characters - _ . remain the same.
The space character ' ' is converted into a plus sign '+'.
All other ASCII characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the character code
All non-ASCII characters are encoded in two steps: first to a sequence of 2 or 3 bytes, using the UTF-8 algorithm; secondly each of these bytes is encoded as "%xx".
s
- The string to be encoded
public static java.lang.String unescapeAnAcceptableFileName(java.lang.String s)
encodeAsAnAcceptableFileName(String)
,
which is to say it decodes any URL encoded string.
s
- an URL encoded string
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |