|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.text.StringUtilities
public class StringUtilities
Miscellaneous utilities functions for strings.
Field Summary | |
---|---|
static java.lang.String |
CHARACTERS_TO_ESCAPE_IN_DOUBLE_QUOTES
Characters that should be escaped with a backslash before output assuming that the character appears inside a double quoted expression in Java. |
static int |
NOT_FOUND
An error code returned by findStart() and
findEnd() that indicates that the substring searched is
only whitespace, so the string that was searched for was never found. |
static int |
UNEXPECTED_CHARACTER
An error code returned by findStart() and
findEnd() that indicates that non-whitespace characters
were found before the string that was searched for. |
Constructor Summary | |
---|---|
protected |
StringUtilities()
Since this class is a static utility class, its sole constructor is protected. |
Method Summary | |
---|---|
static java.lang.StringBuffer |
appendEscapedChar(java.lang.StringBuffer sb,
char c,
java.lang.String charsToEscape)
Append the escaped version of the character to the argument string buffer. |
static java.lang.String |
escape(java.lang.CharSequence cs)
Return escape(cs, CHARACTERS_TO_ESCAPE_IN_DOUBLE_QUOTES) ,
which is suitable for a double-quoted expression in Java. |
static java.lang.String |
escape(java.lang.CharSequence cs,
java.lang.String charsToEscape)
Return the escaped version of the characters in cs . |
static int |
findEnd(java.lang.CharSequence s1,
java.lang.CharSequence s2,
int startIndex)
Call findEnd(s1, s2, startIndex, true) (compare
case-insensitively). |
static int |
findEnd(java.lang.CharSequence s1,
java.lang.CharSequence s2,
int startIndex,
boolean ignoreCase)
Scan s1 for the first occurance of s2 at or
after the start index. |
static MatchResult |
findRawChar(java.lang.CharSequence cs,
int startIndex,
char c)
Find the next raw occurance of c in cs
starting from startIndex. |
static int |
findStart(java.lang.CharSequence s1,
java.lang.CharSequence s2,
int startIndex)
Call findStart(s1, s2, startIndex, true) (compare
case-insensitively). |
static int |
findStart(java.lang.CharSequence s1,
java.lang.CharSequence s2,
int startIndex,
boolean ignoreCase)
Scan s1 for the first occurance of s2 at or
after the start index. |
static int |
findWhitespace(java.lang.CharSequence cs,
int startIndex)
Starting from startIndex , return the index of first
whitespace character in the input sequence. |
static int |
indexOf(java.lang.CharSequence cs,
char c,
int startIndex,
int endIndex)
Find the first index of cs greater than or equal to
startIndex and less than endIndex that
contains the argument character. |
static boolean |
startsWith(java.lang.CharSequence cs,
java.lang.CharSequence prefix,
int toffset,
boolean ignoreCase)
Like String.startsWith(String, int) , but take instances of
CharSequence , and allow the comparison to be done
case-insensitively. |
static java.lang.String |
unbrace(java.lang.CharSequence cs,
char braceChar)
Given a character sequence that starts with a opening C punctuation character and ends with the corresponding C punctutation character, return the contents of the sequence inside the punctuation characters, stripped of whitespace if the brace character is not a quote character. |
static java.lang.String |
unescape(java.lang.CharSequence s)
Convert all escaped characters back to the original ones. |
static java.lang.String |
unescapeQuoted(java.lang.CharSequence cs,
boolean stripQuotes)
Given a non-null string which either starts and ends in double quotes, or has appeared in a double-quoted context, convert all escaped characters back to the original ones. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NOT_FOUND
findStart()
and
findEnd()
that indicates that the substring searched is
only whitespace, so the string that was searched for was never found.
This is less than 0 to avoid confusion with valid indices.
public static final int UNEXPECTED_CHARACTER
findStart()
and
findEnd()
that indicates that non-whitespace characters
were found before the string that was searched for.
This is less than 0 to avoid confusion with valid indices.
public static final java.lang.String CHARACTERS_TO_ESCAPE_IN_DOUBLE_QUOTES
Constructor Detail |
---|
protected StringUtilities()
Method Detail |
---|
public static final java.lang.String unescape(java.lang.CharSequence s) throws java.text.ParseException
java.text.ParseException
public static final java.lang.String unescapeQuoted(java.lang.CharSequence cs, boolean stripQuotes) throws java.text.ParseException
stripQuotes
is
true, make sure the first and last character are double quotes and
remove them.
java.text.ParseException
public static final java.lang.String escape(java.lang.CharSequence cs)
escape(cs, CHARACTERS_TO_ESCAPE_IN_DOUBLE_QUOTES)
,
which is suitable for a double-quoted expression in Java.
public static final java.lang.String escape(java.lang.CharSequence cs, java.lang.String charsToEscape)
cs
.
Any character in charsToEscape
will be escaped with
a backslash before being output.
public static final java.lang.StringBuffer appendEscapedChar(java.lang.StringBuffer sb, char c, java.lang.String charsToEscape)
charsToEscape
will be escaped
with a backslash before being output. Return sb
.
public static final int indexOf(java.lang.CharSequence cs, char c, int startIndex, int endIndex)
cs
greater than or equal to
startIndex
and less than endIndex
that
contains the argument character. If the character cannot be found,
return -1.
public static final int findStart(java.lang.CharSequence s1, java.lang.CharSequence s2, int startIndex)
findStart(s1, s2, startIndex, true)
(compare
case-insensitively).
public static final int findStart(java.lang.CharSequence s1, java.lang.CharSequence s2, int startIndex, boolean ignoreCase)
s1
for the first occurance of s2
at or
after the start index. Skipping only whitespace, return the index of
the character at which s2
appears. If any non-whitespace
character appears before s2
appears, return
NOT_FOUND
. If s2
never appears, return
UNEXPECTED_CHARACTER
. Initial whitespace will be skipped
regardless of what s2
is, so findStart(s1, "",
0)
can be used to located the end of the initial block of
whitespace in s1
. If s1
is all whitespace
starting from startIndex
, and s2
is
""
, return the length of s1
. If
ignoreCase
is true, string comparisons will be made
case-insensitively.
public static final int findEnd(java.lang.CharSequence s1, java.lang.CharSequence s2, int startIndex)
findEnd(s1, s2, startIndex, true)
(compare
case-insensitively).
public static final int findEnd(java.lang.CharSequence s1, java.lang.CharSequence s2, int startIndex, boolean ignoreCase)
s1
for the first occurance of s2
at or
after the start index. Return the index of the character just after
s2
appears. If any non-whitespace character appears before
s2
appears, return NOT_FOUND
. If
s2
never appears, return
UNEXPECTED_CHARACTER
. Note that string comparisons are
made case-sensitively.
public static final boolean startsWith(java.lang.CharSequence cs, java.lang.CharSequence prefix, int toffset, boolean ignoreCase)
String.startsWith(String, int)
, but take instances of
CharSequence
, and allow the comparison to be done
case-insensitively. If prefix
is ""
and
toffset
is within cs
, return true.
public static final int findWhitespace(java.lang.CharSequence cs, int startIndex)
startIndex
, return the index of first
whitespace character in the input sequence. If no whitespace is found,
return NOT_FOUND
.
public static final java.lang.String unbrace(java.lang.CharSequence cs, char braceChar) throws java.text.ParseException
java.text.ParseException
public static final MatchResult findRawChar(java.lang.CharSequence cs, int startIndex, char c) throws java.text.ParseException
c
in cs
starting from startIndex. Occurances of c
that are escaped
will be ignored. Copy startIndex
to the
startIndex
field of the returned result. Set the
endIndex
field of the returned result to the location of
the raw occurance. Set the s
field of the returned result
to the portion of cs
between startIndex
and
endIndex
, except that escaped occurances of c
are unescaped. If no raw occurance of c
occurs before the
end of cs
, treat cs
as if it were terminated
by a raw occurance of c
. If startIndex is the length of
cs
or cs.charAt(startIndex) == '#'
, return a
MatchResult
with its s
field set to the empty
string, and its startIndex
and endIndex
fields set to startIndex
.
java.lang.NullPointerException
- if cs
is null
java.lang.IndexOutOfBoundsException
- if startIndex
is greater
than the length of cs
.
java.text.ParseException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |