phelps.lang

Class Strings

public class Strings extends Object

Extensions to java.lang.String.

Version: $Revision: 1.4 $ $Date: 2003/06/01 07:58:08 $

Field Summary
static Comparator<String>DICTIONARY_CASE_INSENSITIVE_ORDER
static Comparator<String>DICTIONARY_ORDER
static StringPUNCT
Method Summary
static Stringcasify(String words, String wordbreak, Map<String,String> exceptions)
Transform strings of ALL UPPERCASE into Mixed-Case version, with each character after a space kept uppercase, and given table of exceptions.
static intcompareDictionary(String s1, String s2, boolean caseinsensitive)
Compares one String to another in "dictionary order", which means alphabetics compared lexicographically and embedded numbers numerically.
static StringfromPigLatin(String str)
Translate word from Pig Latin.
static byte[]getBytes(String s)
Returns byte array of low byte of each character.
static intminEditDistance(String a, String b)
Returns the minimum number of operations to transform one string into the other.
static StringremoveWhitespace(String txt)
Returns string which has all whitespace characters from txt.
static StringtoASCII7(String txt)
Return 7-bit ASCII transcription of Unicode by removing accents (e.g., "Á"=>"A") and making other character substitutions (e.g., "©" => "(C)").
static Stringtrim(String txt, String chars)
Trim letters in passed chars from ends of word.
static Stringtrim(String txt, String chars, int start, int end)
static StringtrimPunct(String txt)
Trim off punctuation (actually, non-letter or -digit) from ends of txt.
static StringtrimWhitespace(String txt)
static StringtrimWhitespace(String txt, int start, int end)
Can save a String create over String.trim().
static StringvalueOf(String str)
Canonicalizes java.lang.String instances of a single character <= u00ff and those created recently.
static StringvalueOf(StringBuffer sb)
Return possibly shared String.
static StringvalueOf(char ch)

Field Detail

DICTIONARY_CASE_INSENSITIVE_ORDER

public static final Comparator<String> DICTIONARY_CASE_INSENSITIVE_ORDER

DICTIONARY_ORDER

public static final Comparator<String> DICTIONARY_ORDER

PUNCT

public static String PUNCT

Method Detail

casify

public static String casify(String words, String wordbreak, Map<String,String> exceptions)
Transform strings of ALL UPPERCASE into Mixed-Case version, with each character after a space kept uppercase, and given table of exceptions. If a word has any lowercase initially, no case is changed in that word.

For example, UNIX manual pages typically have all uppercase section titles, so this method transforms them into something more easily readable, passing as exceptions a list of odd computer-industry capitalization.

To do: use canonical String if word one-letter long.

See Also: ManualPage

compareDictionary

public static int compareDictionary(String s1, String s2, boolean caseinsensitive)
Compares one String to another in "dictionary order", which means alphabetics compared lexicographically and embedded numbers numerically.

fromPigLatin

public static String fromPigLatin(String str)
Translate word from Pig Latin.

getBytes

public static byte[] getBytes(String s)
Returns byte array of low byte of each character. Like java.lang.String#getBytes() but no encoding, and java.lang.String#getBytes(int, int, byte[], int) but not deprecated.

minEditDistance

public static int minEditDistance(String a, String b)
Returns the minimum number of operations to transform one string into the other. An operation is insert character, delete character, substitute character. Useful to determine if two strings "almost match", as in Strings.minEditDistance("Krzysztof", "Krystof") <= 3.

removeWhitespace

public static String removeWhitespace(String txt)
Returns string which has all whitespace characters from txt.

toASCII7

public static String toASCII7(String txt)
Return 7-bit ASCII transcription of Unicode by removing accents (e.g., "Á"=>"A") and making other character substitutions (e.g., "©" => "(C)"). If no changes to remove, return txt.

trim

public static String trim(String txt, String chars)
Trim letters in passed chars from ends of word.

trim

public static String trim(String txt, String chars, int start, int end)

trimPunct

public static String trimPunct(String txt)
Trim off punctuation (actually, non-letter or -digit) from ends of txt.

trimWhitespace

public static String trimWhitespace(String txt)

trimWhitespace

public static String trimWhitespace(String txt, int start, int end)
Can save a String create over String.trim().

valueOf

public static String valueOf(String str)
Canonicalizes java.lang.String instances of a single character <= u00ff and those created recently.

valueOf

public static String valueOf(StringBuffer sb)
Return possibly shared String. If String is 1-character long and char<256, then guaranteed shared.

valueOf

public static String valueOf(char ch)