Class TextUtil
- java.lang.Object
-
- org.clapper.util.text.TextUtil
-
public final class TextUtil extends java.lang.ObjectStatic class containing miscellaneous text utility methods.
-
-
Field Summary
Fields Modifier and Type Field and Description static char[]HEXADECIMAL_DIGITSSet of digits suitable for encoding a number as a hexadecimal string.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static booleanbooleanFromString(java.lang.String s)Convert a boolean string to a boolean value.static byte[]bytesForHexadecimal(java.lang.String hexString)Takes a string of hexadecimal-encoded byte values and converts it back to an array of bytes.static java.lang.StringcenterString(java.lang.String s, int width)Center a string in a fixed-width field, using blanks for padding.static java.lang.StringcenterString(java.lang.String s, int width, char c)Center a string in a fixed-width field, using the specified character for padding.static java.lang.StringcharToUnicodeEscape(char c)Convert a character to its corresponding Unicode escape sequence.static java.lang.StringcharToUnicodeEscape(char c, java.lang.StringBuilder buf)Convert a character to its corresponding Unicode escape sequence.static java.lang.StringBuilderencodeNumber(int num, int base, char[] digits, java.lang.StringBuilder buf)Encode an integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.static java.lang.StringBuilderencodeNumber(long num, int base, char[] digits, java.lang.StringBuilder buf)Encode a long integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.static java.lang.StringBuilderencodeNumber(short num, int base, char[] digits, java.lang.StringBuilder buf)Encode a short integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.static java.lang.StringBuilderhexadecimalForByte(byte b, java.lang.StringBuilder buf)Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder.static java.lang.StringBuilderhexadecimalForByte(int b, java.lang.StringBuilder buf)Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder.The hexadecimal string uses lower-case digits.static java.lang.StringhexadecimalForBytes(byte[] bytes)Encode an array of bytes as a hexadecimal string, returning the string.static java.lang.StringBuilderhexadecimalForBytes(byte[] bytes, int start, int end, java.lang.StringBuilder buf)Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder.static java.lang.StringBuilderhexadecimalForBytes(int[] bytes, int start, int end, java.lang.StringBuilder buf)Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder.static java.lang.StringhexadecimalForNumber(int num)Encode an integer as a hexadecimal string, returning the hex string.static java.lang.StringBuilderhexadecimalForNumber(int num, java.lang.StringBuilder buf)Encode an integer as a hexadecimal string, appending the result to a StringBuilder.static java.lang.StringhexadecimalForNumber(long num)Encode a long as a hexadecimal string, returning the hex string.static java.lang.StringBuilderhexadecimalForNumber(long num, java.lang.StringBuilder buf)Encode a long as a hexadecimal string, appending the result to a StringBuilder.static java.lang.StringhexadecimalForNumber(short num)Encode a short as a hexadecimal string, returning the hex string.static java.lang.StringBuilderhexadecimalForNumber(short num, java.lang.StringBuilder buf)Encode a short as a hexadecimal string, appending the result to a StringBuilder.static booleanisPrintable(char c)Determine whether a character is printable.static java.lang.Stringjoin(char delim, java.lang.String... strings)Join a set of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.Stringjoin(java.util.Collection<? extends java.lang.Object> objects, char delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.Stringjoin(java.util.Collection<? extends java.lang.Object> objects, java.lang.String delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.Stringjoin(java.lang.String[] strings, char delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.Stringjoin(java.lang.String[] strings, int start, int end, char delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.static java.lang.Stringjoin(java.lang.String[] strings, int start, int end, java.lang.String delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.static java.lang.Stringjoin(java.lang.String[] strings, java.lang.String delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.Stringjoin(java.lang.String delim, java.lang.String... strings)Join a set of strings into one string, putting the specified delimiter between adjacent strings.static java.lang.StringleftJustifyString(java.lang.String s, int width)Left justify a string in a fixed-width field, using blanks for padding.static java.lang.StringleftJustifyString(java.lang.String s, int width, char c)Left justify a string in a fixed-width field, using the specified character for padding.static java.lang.StringrightJustifyString(java.lang.String s, int width)Right justify a string in a fixed-width field, using blanks for padding.static java.lang.StringrightJustifyString(java.lang.String s, int width, char c)Right justify a string in a fixed-width field, using the specified character for padding.static java.lang.StringromanNumeralsForNumber(int n)Get the (upper-case) Roman numeral string for a number.static java.lang.String[]split(java.lang.String s)Split a string on white space, into one or more strings.static java.lang.String[]split(java.lang.String s, boolean preserveEmptyFields)Split a string on white space, into one or more strings.static java.lang.String[]split(java.lang.String s, char delim)Split a string into one or more strings, based on a delimiter.static java.lang.String[]split(java.lang.String s, char delim, boolean preserveEmptyFields)Split a string into one or more strings, based on a delimiter.static intsplit(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection)Split a string into one or more strings, based on a delimiter.static intsplit(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string into one or more strings, based on a delimiter.static intsplit(java.lang.String s, java.util.Collection<java.lang.String> collection)Split a string on white space, into one or more strings.static intsplit(java.lang.String s, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string on white space, into one or more strings.static java.lang.String[]split(java.lang.String s, java.lang.String delimSet)Split a string into one or more strings, based on a set of delimiter.static java.lang.String[]split(java.lang.String s, java.lang.String delimSet, boolean preserveEmptyFields)Split a string into one or more strings, based on a set of delimiter.static intsplit(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection)Split a string into one or more strings, based on a set of delimiter.static intsplit(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string into one or more strings, based on a set of delimiter.static booleanstringIsEmpty(java.lang.String s)Determine whether a given string is empty.
-
-
-
Field Detail
-
HEXADECIMAL_DIGITS
public static final char[] HEXADECIMAL_DIGITS
Set of digits suitable for encoding a number as a hexadecimal string.- See Also:
hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder),encodeNumber(long,int,char[],StringBuilder),encodeNumber(int,int,char[],StringBuilder),encodeNumber(short,int,char[],StringBuilder)
-
-
Method Detail
-
booleanFromString
public static boolean booleanFromString(java.lang.String s) throws java.lang.IllegalArgumentExceptionConvert a boolean string to a boolean value. This method is more generous than java.lang.Boolean.booleanValue(). The following strings (in upper or lower case) are recognized as true: "1", "true", "yes", "y". The following strings (in upper or lower case) are recognized as false: "0", "false", "no", "n".- Parameters:
s- string to convert- Returns:
- true or false
- Throws:
java.lang.IllegalArgumentException- string isn't a boolean
-
split
public static java.lang.String[] split(java.lang.String s)
Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to split- Returns:
- an array of String objects
- See Also:
split(String,boolean),split(String,String),split(String,char),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static java.lang.String[] split(java.lang.String s, boolean preserveEmptyFields)Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitpreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- an array of String objects
- See Also:
split(String),split(String,String),split(String,char),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static int split(java.lang.String s, java.util.Collection<java.lang.String> collection)Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,Collection,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitcollection- where to store the split strings- Returns:
- the number of strings added to the collection
- See Also:
split(String,Collection,boolean),split(String),split(String,String),split(String,char),split(String,char,Collection),split(String,String,Collection)
-
split
public static int split(java.lang.String s, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitcollection- where to store the split stringspreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- the number of strings added to the collection
- See Also:
split(String,Collection),split(String),split(String,String),split(String,char),split(String,char,Collection),split(String,String,Collection)
-
split
public static java.lang.String[] split(java.lang.String s, char delim)Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,char,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelim- the delimiter- Returns:
- an array of String objects
- See Also:
split(String,char,boolean),split(String),split(String,String),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static java.lang.String[] split(java.lang.String s, char delim, boolean preserveEmptyFields)Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelim- the delimiterpreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- an array of String objects
- See Also:
split(String,char),split(String),split(String,String),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static java.lang.String[] split(java.lang.String s, java.lang.String delimSet)Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,String,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelimSet- set of delimiters, or null to use white space- Returns:
- an array of String objects
- See Also:
split(String,String,boolean),split(String),split(String,char),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static java.lang.String[] split(java.lang.String s, java.lang.String delimSet, boolean preserveEmptyFields)Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelimSet- set of delimiters, or null to use white spacepreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- an array of String objects
- See Also:
split(String,String),split(String),split(String,char),split(String,Collection),split(String,char,Collection),split(String,String,Collection)
-
split
public static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection)Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,char,Collection,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelim- the delimitercollection- where to store the split strings- Returns:
- the number of String objects added to the collection
- See Also:
split(String,char,Collection,boolean),split(String),split(String,char),split(String,Collection),split(String,String),split(String,String,Collection)
-
split
public static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
- Parameters:
s- the string to splitdelim- the delimitercollection- where to store the split stringspreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- the number of String objects added to the collection
- See Also:
split(String,char,Collection),split(String),split(String,char),split(String,Collection),split(String,String),split(String,String,Collection)
-
split
public static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection)Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the
split(String,String,Collection,boolean)method.Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to thesplit(String,String,Collection,boolean)method.- Parameters:
s- the string to splitdelimSet- set of delimiterscollection- where to store the split strings- Returns:
- the number of String objects added to the collection
- See Also:
split(String,String,Collection,boolean),split(String),split(String,char),split(String,Collection),split(String,String),split(String,char,Collection)
-
split
public static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This method uses a StringTokenizer to do the actual work.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to thesplit(String,String,Collection,boolean)method.- Parameters:
s- the string to splitdelimSet- set of delimiterscollection- where to store the split stringspreserveEmptyFields- Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)- Returns:
- the number of String objects added to the collection
- See Also:
split(String,String,Collection),split(String),split(String,char),split(String,Collection),split(String,String),split(String,char,Collection)
-
join
public static java.lang.String join(java.lang.String[] strings, java.lang.String delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.- Parameters:
strings- the strings to be joineddelim- the delimiter string- Returns:
- the joined string, or "" if the array is empty.
- See Also:
split(String,String),join(String[],char)
-
join
public static java.lang.String join(java.lang.String delim, java.lang.String... strings)Join a set of strings into one string, putting the specified delimiter between adjacent strings. This version of join() supports the new Java variable argument syntax.- Parameters:
delim- the delimiter stringstrings- the strings to be joined- Returns:
- the joined string, or "" if the array is empty.
- See Also:
split(String,char),join(String[],String)
-
join
public static java.lang.String join(java.lang.String[] strings, char delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings.- Parameters:
strings- the strings to be joineddelim- the delimiter character- Returns:
- the joined string, or "" if the array is empty.
- See Also:
split(String,char),join(String[],String)
-
join
public static java.lang.String join(java.lang.String[] strings, int start, int end, char delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.- Parameters:
strings- the strings to be joinedstart- starting indexend- one past the ending indexdelim- the delimiter character- Returns:
- the joined string, or "" if the array is empty.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- bad value for start or end- See Also:
split(String,char),join(String[],String)
-
join
public static java.lang.String join(java.lang.String[] strings, int start, int end, java.lang.String delim)Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.- Parameters:
strings- the strings to be joinedstart- starting indexend- one past the ending indexdelim- the delimiter string- Returns:
- the joined string, or "" if the array is empty.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- bad value for start or end- See Also:
split(String,char),join(String[],String)
-
join
public static java.lang.String join(char delim, java.lang.String... strings)Join a set of strings into one string, putting the specified delimiter between adjacent strings. This version of join() supports the new Java variable argument syntax.- Parameters:
delim- the delimiter characterstrings- the strings to be joined- Returns:
- the joined string, or "" if the array is empty.
- See Also:
split(String,char),join(String[],String)
-
join
public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, java.lang.String delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.- Parameters:
objects- A collection the items to be joined. This collection can contain objects of any type; each object's toString() method is called to produce the string to be joined.delim- the delimiter string- Returns:
- the joined string, or "" if the collection is empty.
- See Also:
split(String,String,Collection),join(Collection,char)
-
join
public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, char delim)Join a set of strings into one string, putting the specified delimiter between adjacent strings.- Parameters:
objects- A collection the items to be joined. This collection can contain objects of any type; each object's toString() method is called to produce the string to be joined.delim- the delimiter character- Returns:
- the joined string, or "" if the collection is empty.
- See Also:
split(String,char,Collection),join(Collection,String)
-
stringIsEmpty
public static boolean stringIsEmpty(java.lang.String s)
Determine whether a given string is empty. A string is empty if it is null, zero-length, or comprised entirely of white space. This method is more efficient than calling s.trim().length(), because it does not create a new string just to test its length.- Parameters:
s- the string to test- Returns:
- true if it's empty, false if not.
-
rightJustifyString
public static java.lang.String rightJustifyString(java.lang.String s, int width)Right justify a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field width- Returns:
- a right-justified version of the string
- See Also:
rightJustifyString(String,int,char),leftJustifyString(String,int),centerString(String,int)
-
rightJustifyString
public static java.lang.String rightJustifyString(java.lang.String s, int width, char c)Right justify a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field widthc- the pad character- Returns:
- a right-justified version of the string
- See Also:
rightJustifyString(String,int),leftJustifyString(String,int,char),centerString(String,int,char)
-
leftJustifyString
public static java.lang.String leftJustifyString(java.lang.String s, int width)Left justify a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field width- Returns:
- a left-justified version of the string
- See Also:
leftJustifyString(String,int,char),rightJustifyString(String,int),centerString(String,int)
-
leftJustifyString
public static java.lang.String leftJustifyString(java.lang.String s, int width, char c)Left justify a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field widthc- the pad character- Returns:
- a left-justified version of the string
- See Also:
leftJustifyString(String,int),rightJustifyString(String,int,char),centerString(String,int,char)
-
centerString
public static java.lang.String centerString(java.lang.String s, int width)Center a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field width- Returns:
- a centered version of the string
- See Also:
centerString(String,int,char),rightJustifyString(String,int),leftJustifyString(String,int)
-
centerString
public static java.lang.String centerString(java.lang.String s, int width, char c)Center a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.- Parameters:
s- the stringwidth- the desired field widthc- the pad character- Returns:
- a right-justified version of the string
- See Also:
centerString(String,int,char),leftJustifyString(String,int,char),rightJustifyString(String,int,char)
-
hexadecimalForByte
public static java.lang.StringBuilder hexadecimalForByte(byte b, java.lang.StringBuilder buf)Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder. The hexadecimal string uses lower-case digits. Note that the byte type in Java is signed. Use the other version ofhexadecimalForByte(int,StringBuilder)if you want to pass an unsigned byte value.- Parameters:
b- the bytebuf- the StringBuilder to which to append the hex string- Returns:
- a reference to the StringBuilder, for convenience
- See Also:
hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder),bytesForHexadecimal(String)
-
hexadecimalForByte
public static java.lang.StringBuilder hexadecimalForByte(int b, java.lang.StringBuilder buf)Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder.The hexadecimal string uses lower-case digits. in lower-case. This version of hexadecimalForByte is suitable for use with unsigned values.- Parameters:
b- the bytebuf- the StringBuilder to which to append the hex string- Returns:
- a reference to the StringBuilder, for convenience
- See Also:
hexadecimalForByte(byte,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder),bytesForHexadecimal(String)
-
hexadecimalForBytes
public static java.lang.StringBuilder hexadecimalForBytes(byte[] bytes, int start, int end, java.lang.StringBuilder buf)Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder. Note that the byte type in Java is signed. Use the other version ofhexadecimalForBytes(int[],int,int,StringBuilder)if you want to pass signed byte values.- Parameters:
bytes- The array of bytesstart- starting index in byte arrayend- one past ending index in byte array (thus, bytes.length is a valid value)buf- Where to append the result- Returns:
- a reference to the StringBuilder, for convenience
- See Also:
hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),bytesForHexadecimal(String)
-
hexadecimalForBytes
public static java.lang.String hexadecimalForBytes(byte[] bytes)
Encode an array of bytes as a hexadecimal string, returning the string. Calling this method is equivalent to:hexadecimalForBytes(buf, 0, buf.length, new StringBuilder()).toString()
- Parameters:
bytes- The array of bytes- Returns:
- a reference to the StringBuilder, for convenience
- See Also:
hexadecimalForBytes(byte[],int,int,StringBuilder)
-
hexadecimalForBytes
public static java.lang.StringBuilder hexadecimalForBytes(int[] bytes, int start, int end, java.lang.StringBuilder buf)Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder. Note that this method takes an int array; however, it only examines the low-order byte of each integer. It's suitable for use with unsigned values. Use the other version ofhexadecimalForBytes(byte[],int,int,StringBuilder)if you want to pass signed byte values.- Parameters:
bytes- The array of bytesstart- starting index in byte arrayend- one past ending index in byte array (thus, bytes.length is a valid value)buf- Where to append the result- Returns:
- the StringBuilder, for convenience
- See Also:
hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),bytesForHexadecimal(String)
-
hexadecimalForNumber
public static java.lang.StringBuilder hexadecimalForNumber(int num, java.lang.StringBuilder buf)Encode an integer as a hexadecimal string, appending the result to a StringBuilder. This method uses encodeNumber() to perform the actual encoding.- Parameters:
num- The integer to encodebuf- Where to append the result- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(int,int,char[],StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
hexadecimalForNumber
public static java.lang.String hexadecimalForNumber(int num)
Encode an integer as a hexadecimal string, returning the hex string. This method uses encodeNumber() to perform the actual encoding.- Parameters:
num- The integer to encode- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(int,int,char[],StringBuilder),hexadecimalForNumber(short),hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(long),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
hexadecimalForNumber
public static java.lang.StringBuilder hexadecimalForNumber(long num, java.lang.StringBuilder buf)Encode a long as a hexadecimal string, appending the result to a StringBuilder.- Parameters:
num- The long to encodebuf- Where to append the result- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(long,int,char[],StringBuilder),hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
hexadecimalForNumber
public static java.lang.String hexadecimalForNumber(long num)
Encode a long as a hexadecimal string, returning the hex string. This method uses encodeNumber() to perform the actual encoding.- Parameters:
num- The long integer to encode- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(int,int,char[],StringBuilder),hexadecimalForNumber(short),hexadecimalForNumber(long,StringBuilder),hexadecimalForNumber(int),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
hexadecimalForNumber
public static java.lang.String hexadecimalForNumber(short num)
Encode a short as a hexadecimal string, returning the hex string. This method uses encodeNumber() to perform the actual encoding.- Parameters:
num- The short integer to encode- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(int,int,char[],StringBuilder),hexadecimalForNumber(long),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(int),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
hexadecimalForNumber
public static java.lang.StringBuilder hexadecimalForNumber(short num, java.lang.StringBuilder buf)Encode a short as a hexadecimal string, appending the result to a StringBuilder.- Parameters:
num- The short integer to encodebuf- Where to append the result- Returns:
- the StringBuilder, for convenience
- See Also:
hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForNumber(short),encodeNumber(short,int,char[],StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
encodeNumber
public static java.lang.StringBuilder encodeNumber(long num, int base, char[] digits, java.lang.StringBuilder buf)Encode a long integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); long num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of hexadecimal digits. (See
HEXADECIMAL_DIGITS.) However, it's usually simpler just to use one of the hexadecimalForNumber() methods().- Parameters:
num- The long integer to encodebase- The base in which to encode the numberdigits- The array of digit characters to use for the encoding. This array must be at least base characters in length. digits[0] represents the numeral to use for 0, digits[1] represents the numeral to use for 1, etc.buf- The StringBuilder to which to append the encoded number string- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(short,int,char[],StringBuilder),encodeNumber(int,int,char[],StringBuilder),hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
encodeNumber
public static java.lang.StringBuilder encodeNumber(short num, int base, char[] digits, java.lang.StringBuilder buf)Encode a short integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); short num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of hexadecimal digits. (See
HEXADECIMAL_DIGITS.) However, it's usually simpler just to use one of the hexadecimalForNumber() methods().- Parameters:
num- The short integer to encodebase- The base in which to encode the numberdigits- The array of digit characters to use for the encoding. This array must be at least base characters in length. digits[0] represents the numeral to use for 0, digits[1] represents the numeral to use for 1, etc.buf- The StringBuilder to which to append the encoded number string- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(int,int,char[],StringBuilder),encodeNumber(long,int,char[],StringBuilder),hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
encodeNumber
public static java.lang.StringBuilder encodeNumber(int num, int base, char[] digits, java.lang.StringBuilder buf)Encode an integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); int num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of hexadecimal digits. (See
HEXADECIMAL_DIGITS.) However, it's usually simpler just to use one of the hexadecimalForNumber() methods().- Parameters:
num- The integer to encodebase- The base in which to encode the numberdigits- The array of digit characters to use for the encoding. This array must be at least base characters in length. digits[0] represents the numeral to use for 0, digits[1] represents the numeral to use for 1, etc.buf- The StringBuilder to which to append the encoded number string- Returns:
- the StringBuilder, for convenience
- See Also:
encodeNumber(short,int,char[],StringBuilder),encodeNumber(long,int,char[],StringBuilder),hexadecimalForNumber(int,StringBuilder),hexadecimalForNumber(short,StringBuilder),hexadecimalForNumber(long,StringBuilder),hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
bytesForHexadecimal
public static byte[] bytesForHexadecimal(java.lang.String hexString) throws java.lang.NumberFormatExceptionTakes a string of hexadecimal-encoded byte values and converts it back to an array of bytes. The string may or may not contain white space; all white space is stripped before parsing begins. However, white space cannot occur between the digits for a byte; it must only occur between bytes. That is, "6f a1" is legal, while "6 f a 1" is not. Each byte must be encoded as a 2-digits hexadecimal value; as a consequence, the input string must have an even number of characters, once all white space has been stripped. The hexadecimal digits "a" through "f" may be in upper- or lower-case. An illegal hexadecimal string will result in a NumberFormatException. The following strings are examples of legal input to this method:
1F 66756c6c74696c742e636f6d 42 72 69 61 6e 20 43 6c 61 70 70 65 72 49 2D41 63 63656C
The following strings are examples of illegal input:
1X 6 6f a 1 6675-6c6c-7469-6c742e-636f6d
- Parameters:
hexString- the hex string to convert- Returns:
- an array of bytes representing the decoded hex string
- Throws:
java.lang.NumberFormatException- if the hex string is invalid- See Also:
hexadecimalForByte(byte,StringBuilder),hexadecimalForByte(int,StringBuilder),hexadecimalForBytes(byte[],int,int,StringBuilder),hexadecimalForBytes(int[],int,int,StringBuilder)
-
romanNumeralsForNumber
public static java.lang.String romanNumeralsForNumber(int n)
Get the (upper-case) Roman numeral string for a number.- Parameters:
n- the number; must be positive- Returns:
- the roman number string
-
charToUnicodeEscape
public static java.lang.String charToUnicodeEscape(char c, java.lang.StringBuilder buf)Convert a character to its corresponding Unicode escape sequence.- Parameters:
c- the characterbuf- where to store the result- Returns:
- the contents of buf, as a string
- See Also:
charToUnicodeEscape(char)
-
charToUnicodeEscape
public static java.lang.String charToUnicodeEscape(char c)
Convert a character to its corresponding Unicode escape sequence.- Parameters:
c- the character- See Also:
charToUnicodeEscape(char)
-
isPrintable
public static boolean isPrintable(char c)
Determine whether a character is printable. This method uses a simple definition of "printable" that doesn't take into account specific locales. A character is assumed to be printable if (a) it's in the Basic Latin, Latin 1 Supplement, or Extended Latin A Unicode block, and (b) its type, as returned by java.lang.Character.getType() is one of:- Character.OTHER_PUNCTUATION
- Character.START_PUNCTUATION
- Character.END_PUNCTUATION
- Character.CONNECTOR_PUNCTUATION
- Character.CURRENCY_SYMBOL
- Character.MATH_SYMBOL
- Character.MODIFIER_SYMBOL
- Character.UPPERCASE_LETTER
- Character.LOWERCASE_LETTER
- Character.DECIMAL_DIGIT_NUMBER
- Character.SPACE_SEPARATOR
- Character.DASH_PUNCTUATION
All other characters are assumed to be non-printable, even if they could actually be printed in the current locale or on some printer.
- Parameters:
c- the character to test- Returns:
- whether or not it is non-
-
-
DMelt 3.0 © DataMelt by jWork.ORG