com.sun.tools.javac.util
Class Convert

java.lang.Object
  extended by com.sun.tools.javac.util.Convert

public class Convert
extends java.lang.Object

Utility class for static conversion methods between numbers and strings in various formats.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Constructor Summary
Convert()
           
 
Method Summary
static byte[] chars2utf(char[] src)
          Return all characters in given array as an array of bytes in Utf8 representation.
static int chars2utf(char[] src, int sindex, byte[] dst, int dindex, int len)
          Copy characters in source array to bytes in target array, converting them to Utf8 representation.
static byte[] chars2utf(char[] src, int sindex, int len)
          Return characters as an array of bytes in Utf8 representation.
static List<Name> enclosingCandidates(Name name)
           
static java.lang.String escapeUnicode(java.lang.String s)
          Escape all unicode characters in string.
private static boolean isPrintableAscii(char ch)
          Is a character printable ASCII?
static Name packagePart(Name classname)
          Return the package name of a class name, excluding the trailing '.', "" if not existent.
static java.lang.String packagePart(java.lang.String classname)
           
static java.lang.String quote(char ch)
          Escapes a character if it has an escape sequence or is non-printable ASCII.
static java.lang.String quote(java.lang.String s)
          Escapes each character in a string that has an escape sequence or is non-printable ASCII.
static Name shortName(Name classname)
          Return the last part of a class name.
static java.lang.String shortName(java.lang.String classname)
           
static int string2int(java.lang.String s, int radix)
          Convert string to integer.
static long string2long(java.lang.String s, int radix)
          Convert string to long integer.
static byte[] string2utf(java.lang.String s)
          Return string as an array of bytes in in Utf8 representation.
static char[] utf2chars(byte[] src)
          Return all bytes of a given array in Utf8 representation as an array of characters.
static int utf2chars(byte[] src, int sindex, char[] dst, int dindex, int len)
          Convert `len' bytes from utf8 to characters.
static char[] utf2chars(byte[] src, int sindex, int len)
          Return bytes in Utf8 representation as an array of characters.
static java.lang.String utf2string(byte[] src)
          Return all bytes of a given array in Utf8 representation as a string.
static java.lang.String utf2string(byte[] src, int sindex, int len)
          Return bytes in Utf8 representation as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Convert

public Convert()
Method Detail

string2int

public static int string2int(java.lang.String s,
                             int radix)
                      throws java.lang.NumberFormatException
Convert string to integer.

Throws:
java.lang.NumberFormatException

string2long

public static long string2long(java.lang.String s,
                               int radix)
                        throws java.lang.NumberFormatException
Convert string to long integer.

Throws:
java.lang.NumberFormatException

utf2chars

public static int utf2chars(byte[] src,
                            int sindex,
                            char[] dst,
                            int dindex,
                            int len)
Convert `len' bytes from utf8 to characters. Parameters are as in System.arraycopy Return first index in `dst' past the last copied char.

Parameters:
src - The array holding the bytes to convert.
sindex - The start index from which bytes are converted.
dst - The array holding the converted characters..
dindex - The start index from which converted characters are written.
len - The maximum number of bytes to convert.

utf2chars

public static char[] utf2chars(byte[] src,
                               int sindex,
                               int len)
Return bytes in Utf8 representation as an array of characters.

Parameters:
src - The array holding the bytes.
sindex - The start index from which bytes are converted.
len - The maximum number of bytes to convert.

utf2chars

public static char[] utf2chars(byte[] src)
Return all bytes of a given array in Utf8 representation as an array of characters.

Parameters:
src - The array holding the bytes.

utf2string

public static java.lang.String utf2string(byte[] src,
                                          int sindex,
                                          int len)
Return bytes in Utf8 representation as a string.

Parameters:
src - The array holding the bytes.
sindex - The start index from which bytes are converted.
len - The maximum number of bytes to convert.

utf2string

public static java.lang.String utf2string(byte[] src)
Return all bytes of a given array in Utf8 representation as a string.

Parameters:
src - The array holding the bytes.

chars2utf

public static int chars2utf(char[] src,
                            int sindex,
                            byte[] dst,
                            int dindex,
                            int len)
Copy characters in source array to bytes in target array, converting them to Utf8 representation. The target array must be large enough to hold the result. returns first index in `dst' past the last copied byte.

Parameters:
src - The array holding the characters to convert.
sindex - The start index from which characters are converted.
dst - The array holding the converted characters..
dindex - The start index from which converted bytes are written.
len - The maximum number of characters to convert.

chars2utf

public static byte[] chars2utf(char[] src,
                               int sindex,
                               int len)
Return characters as an array of bytes in Utf8 representation.

Parameters:
src - The array holding the characters.
sindex - The start index from which characters are converted.
len - The maximum number of characters to convert.

chars2utf

public static byte[] chars2utf(char[] src)
Return all characters in given array as an array of bytes in Utf8 representation.

Parameters:
src - The array holding the characters.

string2utf

public static byte[] string2utf(java.lang.String s)
Return string as an array of bytes in in Utf8 representation.


quote

public static java.lang.String quote(java.lang.String s)
Escapes each character in a string that has an escape sequence or is non-printable ASCII. Leaves non-ASCII characters alone.


quote

public static java.lang.String quote(char ch)
Escapes a character if it has an escape sequence or is non-printable ASCII. Leaves non-ASCII characters alone.


isPrintableAscii

private static boolean isPrintableAscii(char ch)
Is a character printable ASCII?


escapeUnicode

public static java.lang.String escapeUnicode(java.lang.String s)
Escape all unicode characters in string.


shortName

public static Name shortName(Name classname)
Return the last part of a class name.


shortName

public static java.lang.String shortName(java.lang.String classname)

packagePart

public static Name packagePart(Name classname)
Return the package name of a class name, excluding the trailing '.', "" if not existent.


packagePart

public static java.lang.String packagePart(java.lang.String classname)

enclosingCandidates

public static List<Name> enclosingCandidates(Name name)