cs132.util
Class StringUtil

java.lang.Object
  extended by cs132.util.StringUtil

public class StringUtil
extends Object


Field Summary
static String Hex
           
static String NL
          The platform-specific end-of-line marker (Usually "\n" on Unix and "\r\n" on Windows).
static Charset UTF8
          A convenience instance of the UTF-8 Charset object.
 
Method Summary
static String decode(Charset charset, byte[] data)
           
static String decode(Charset charset, byte[] data, int offset, int length)
           
static String decode(CharsetDecoder decoder, byte[] data)
           
static String decode(CharsetDecoder decoder, byte[] data, int offset, int length)
           
static byte[] getUTF8(String s)
          Return the UTF-8-encoded equivalent of the given string.
static void hex(StringBuilder buf, char c)
          Append the hex value of the given character.
static void hex2(StringBuilder buf, byte c)
          Append the 2-digit hex value of the given character's low byte.
static void hex4(StringBuilder buf, char c)
          Append the 4-digit hex value of the given character.
static String join(Iterable<? extends CharSequence> items, String sep)
          Equivalent to: join(items, sep, "")
static String join(Iterable<? extends CharSequence> items, String sep, String empty)
          Concatenate the strings in 'items', separated by the string in 'sep'.
static String jq(String s)
           Return a Java string literal that is equivalent to the given string.
static void jq(StringBuilder buf, String s)
          Equivalent to jq(String), except it appends the result to a StringBuilder instead of returning it as a string.
static void jqc(StringBuilder buf, String s)
          Equivalent to jq(StringBuilder,String), except it doesn't include the leading and trailing quote characters.
static String readableChar(char c)
           Human-readable representation of a character.
static void readableChar(StringBuilder buf, char c)
          Equivalent to readableChar(char), except it appends the result to a StringBuilder instead of returning it as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NL

public static final String NL
The platform-specific end-of-line marker (Usually "\n" on Unix and "\r\n" on Windows).


UTF8

public static final Charset UTF8
A convenience instance of the UTF-8 Charset object. Obtained with: Charset.forName("UTF-8").


Hex

public static final String Hex
See Also:
Constant Field Values
Method Detail

getUTF8

public static byte[] getUTF8(String s)
Return the UTF-8-encoded equivalent of the given string.


jq

public static String jq(String s)

Return a Java string literal that is equivalent to the given string.


jq

public static void jq(StringBuilder buf,
                      String s)
Equivalent to jq(String), except it appends the result to a StringBuilder instead of returning it as a string.


jqc

public static void jqc(StringBuilder buf,
                       String s)
Equivalent to jq(StringBuilder,String), except it doesn't include the leading and trailing quote characters.


readableChar

public static String readableChar(char c)

Human-readable representation of a character. Most "normal" characters are simply placed between quotes.


readableChar

public static void readableChar(StringBuilder buf,
                                char c)
Equivalent to readableChar(char), except it appends the result to a StringBuilder instead of returning it as a string.


hex2

public static void hex2(StringBuilder buf,
                        byte c)
Append the 2-digit hex value of the given character's low byte.


hex4

public static void hex4(StringBuilder buf,
                        char c)
Append the 4-digit hex value of the given character.


hex

public static void hex(StringBuilder buf,
                       char c)
Append the hex value of the given character. Will use between 1 and 4 digits (leading zeros are ommitted).


join

public static String join(Iterable<? extends CharSequence> items,
                          String sep)
Equivalent to: join(items, sep, "")


join

public static String join(Iterable<? extends CharSequence> items,
                          String sep,
                          String empty)
Concatenate the strings in 'items', separated by the string in 'sep'.

Parameters:
items - The strings to concatenate.
sep - The string to use as a separator.
empty - The string to return if 'items' is an empty list.

decode

public static String decode(Charset charset,
                            byte[] data)
                     throws CharacterCodingException
Throws:
CharacterCodingException

decode

public static String decode(Charset charset,
                            byte[] data,
                            int offset,
                            int length)
                     throws CharacterCodingException
Throws:
CharacterCodingException

decode

public static String decode(CharsetDecoder decoder,
                            byte[] data)
                     throws CharacterCodingException
Throws:
CharacterCodingException

decode

public static String decode(CharsetDecoder decoder,
                            byte[] data,
                            int offset,
                            int length)
                     throws CharacterCodingException
Throws:
CharacterCodingException