|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlapisx.util.Str
String utility routines.
Constructor Summary | |
Str()
|
Method Summary | |
static String |
abbreviate(String s,
int max)
Abbreviate a string. |
static String |
abbreviateLines(String s,
int maxLines,
String message)
Abbreviate a multi-line string. |
static String |
after(String s,
String pat)
Split string around a substring match and return suffix. |
static String |
before(String s,
String pat)
Split string around a substring match and return prefix. |
static String |
compressWhitespace(String s)
Compress whitespace. |
static boolean |
endsWithIgnoreCase(String s,
String suffix)
Like String.endsWith, but case-insensitive. |
static String |
escape(String subject,
char escapeChar,
String metachars)
Escapes metacharacters in a string. |
static String |
escape(String subject,
String chars,
char escapeChar,
String metachars)
Escapes characters in a string. |
static int |
indexOfAnyChar(String subject,
String chars)
Find first occurence of any of a set of characters. |
static int |
indexOfAnyChar(String subject,
String chars,
int start)
Find first occurence of any of a set of characters, starting at a specified index. |
static boolean |
isWhitespace(String s)
Test if string contains only whitespace. |
static String |
join(String[] list,
String sep)
Concatenate an array of strings. |
static String |
longestCommonPrefix(String s,
String t)
Find longest common prefix of two strings. |
static String |
longestCommonPrefixIgnoreCase(String s,
String t)
Find longest common prefix of two strings, ignoring case. |
static int |
longestCommonPrefixLength(String s,
String t)
|
static int |
longestCommonPrefixLengthIgnoreCase(String s,
String t)
|
static String |
longestCommonSuffix(String s,
String t)
Find longest common suffix of two strings. |
static String |
longestCommonSuffixIgnoreCase(String s,
String t)
Find longest common suffix of two strings, ignoring case. |
static int |
longestCommonSuffixLength(String s,
String t)
|
static int |
longestCommonSuffixLengthIgnoreCase(String s,
String t)
|
static Number |
parseNumber(String s)
|
static String |
repeat(String s,
int n)
Generate a string by concatenating n copies of another string. |
static String |
replace(String subject,
String original,
String replacement)
Replace all occurences of a string. |
static String |
reverse(String s)
Reverse a string. |
static boolean |
startsWithIgnoreCase(String s,
String prefix)
Like String.startsWith, but case-insensitive. |
static String |
unescape(String subject,
char escapeChar,
String metachars,
String chars,
boolean keepUntranslatedEscapes)
Translate escape sequences (e.g. |
static String |
untabify(String s,
int tabsize)
Expands tabs to spaces. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Str()
Method Detail |
public static int indexOfAnyChar(String subject, String chars)
subject
- String in which to searchchars
- Characters to search for
public static int indexOfAnyChar(String subject, String chars, int start)
subject
- String in which to searchchars
- Characters to search forstart
- Starting offset to search from
public static String replace(String subject, String original, String replacement)
subject
- String in which to searchoriginal
- String to search for in subjectreplacement
- String to substitute
public static String escape(String subject, char escapeChar, String metachars)
subject
- String in which metacharacters are to be escapedescapeChar
- the escape character (e.g., \)metachars
- the metacharacters that should be escaped
public static String escape(String subject, String chars, char escapeChar, String metachars)
subject
- String in which metacharacters are to be escapedchars
- Characters that need to be escaped (e.g. "\b\t\r\n\\")escapeChar
- the escape character (e.g., '\\')metachars
- escape code letters corresponding to each letter in chars (e.g. "btrn\\")
Must have metachars.length () == chars.length().
public static String unescape(String subject, char escapeChar, String metachars, String chars, boolean keepUntranslatedEscapes)
subject
- String in which metacharacters are to be escapedescapeChar
- the escape character (e.g., \)metachars
- letters representing escape codes (typically "btrn\\")chars
- characters corresponding to metachars (typically "\b\t\r\n\\").
Must have chars.length () == metachars.length().keepUntranslatedEscapes
- Controls behavior on unknown escape sequences
(see below).
public static Number parseNumber(String s) throws NumberFormatException
NumberFormatException
public static String repeat(String s, int n)
s
- String to repeatn
- number of times to repeat s
public static String compressWhitespace(String s)
s
- String to compress
public static boolean isWhitespace(String s)
s
- String to test
public static String join(String[] list, String sep)
list
- Array of strings to concatenatesep
- Separator to insert between each string
public static String abbreviate(String s, int max)
s
- String to abbreviatemax
- Maximum length of returned string; must be at least 5
s with linebreaks removed and enough characters removed from
the middle (replaced by "...") to make length <= maxpublic static String abbreviateLines(String s, int maxLines, String message)
s
- String to abbreviatemaxLines
- Max number of lines in returned string; must be at least 3message
- Message to replace removed lines with; should end with
\n, but may be multiple lines. Occurrences of %d are replaced with
the number of lines removed.
s with enough whole lines removed from
the middle (replaced by message) to make its length in lines <= maxpublic static String before(String s, String pat)
s
- String to splitpat
- Substring to search for in s
public static String after(String s, String pat)
s
- String to splitpat
- Substring to search for in s
public static boolean startsWithIgnoreCase(String s, String prefix)
public static boolean endsWithIgnoreCase(String s, String suffix)
public static String untabify(String s, int tabsize)
public static String reverse(String s)
s
- String to reverse
public static String longestCommonPrefix(String s, String t)
public static int longestCommonPrefixLength(String s, String t)
public static String longestCommonSuffix(String s, String t)
public static int longestCommonSuffixLength(String s, String t)
public static String longestCommonPrefixIgnoreCase(String s, String t)
public static int longestCommonPrefixLengthIgnoreCase(String s, String t)
public static String longestCommonSuffixIgnoreCase(String s, String t)
public static int longestCommonSuffixLengthIgnoreCase(String s, String t)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |