com.bluemarsh.jswat.util
Class StringUtils
java.lang.Object
|
+--com.bluemarsh.jswat.util.StringUtils
- public class StringUtils
- extends java.lang.Object
Provides utility methods for handling Strings.
- Author:
- Nathan Fiedler
Field Summary |
protected static java.lang.String[] |
zeros
Array of zeros for padding numbers. |
Method Summary |
static java.lang.String |
cleanForPrinting(java.lang.String input,
int maxLen)
Substitute the slash escaped printable characters with the
escaped equivalents, so the string can be displayed properly. |
static int |
indexOfUnescaped(java.lang.String s,
char c)
Returns the index within this string of the first occurrence of the
specified character, not preceeded by a forward slash (\). |
static int |
indexOfUnescaped(java.lang.String s,
int ch,
int fromIndex)
Returns the index within this string of the first occurrence of the
specified character, not preceeded by a forward slash (\), starting
the search at the specified index. |
static java.lang.String |
toHexString(int i)
Converts the given integer to a four-digit, hexadecimal string,
padding with zeros as needed. |
static java.lang.String[] |
tokenize(java.lang.String input)
Take the given string and chop it up into a series of strings
on whitespace boundries. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
zeros
protected static java.lang.String[] zeros
- Array of zeros for padding numbers.
StringUtils
public StringUtils()
cleanForPrinting
public static java.lang.String cleanForPrinting(java.lang.String input,
int maxLen)
- Substitute the slash escaped printable characters with the
escaped equivalents, so the string can be displayed properly.
Also optionally limit the length of the string.
- Parameters:
input
- string to be processed (may be null).maxLen
- maximum length of output string; 0 for no limit.- Returns:
- string with escapes escaped and length limited.
indexOfUnescaped
public static int indexOfUnescaped(java.lang.String s,
char c)
- Returns the index within this string of the first occurrence of the
specified character, not preceeded by a forward slash (\). If a
character with value
ch
occurs in the character
sequence represented by this String
object, then the
index of the first such occurrence is returned -- that is, the
smallest value k such that:
this.charAt(k) == ch
is true
. If no such character occurs in this string,
then -1
is returned.
- Parameters:
s
- the string.ch
- a character.- Returns:
- the index of the first occurrence of the character in the
character sequence represented by this object, or
-1
if the character does not occur.
indexOfUnescaped
public static int indexOfUnescaped(java.lang.String s,
int ch,
int fromIndex)
- Returns the index within this string of the first occurrence of the
specified character, not preceeded by a forward slash (\), starting
the search at the specified index.
If a character with value ch
occurs in the character
sequence represented by this String
object at an index
no smaller than fromIndex
, then the index of the first
such occurrence is returned--that is, the smallest value k
such that:
(this.charAt(k) == ch) && (k >= fromIndex)
is true. If no such character occurs in this string at or after
position fromIndex
, then -1
is returned.
There is no restriction on the value of fromIndex
.
If it is negative, it has the same effect as if it were zero: this
entire string may be searched. If it is greater than the length of
this string, it has the same effect as if it were equal to the length
of this string: -1
is returned.
- Parameters:
s
- the string.ch
- a character.fromIndex
- the index to start the search from.- Returns:
- the index of the first occurrence of the character in the
character sequence represented by this object that is greater
than or equal to
fromIndex
, or -1
if the character does not occur.
toHexString
public static java.lang.String toHexString(int i)
- Converts the given integer to a four-digit, hexadecimal string,
padding with zeros as needed.
- Parameters:
i
- integer to convert.- Returns:
- String representation.
tokenize
public static java.lang.String[] tokenize(java.lang.String input)
- Take the given string and chop it up into a series of strings
on whitespace boundries. This is useful for trying to get an
array of strings out of the resource file. If input is null,
returns a zero-length array of String.
- Parameters:
input
- string to be split apart.- Returns:
- array of strings from input.