com.vgrs.xcode.common
Class Utf16

java.lang.Object
  extended by com.vgrs.xcode.common.Utf16

public class Utf16
extends java.lang.Object

Statically implements various operations surrounding UTF-16 codepoints.


Field Summary
static char HYPHEN
          Constants
 
Constructor Summary
Utf16()
           
 
Method Summary
static byte[] contract(char[] aInput)
          Contract a 16 bit sequence into 8 bits.
static char[] contract(int[] aInput)
          Contract a 32 bit sequence into 16 bits.
static char[] expand(byte[] aInput)
          Expand a 8 bit sequence into 16 bits.
static int[] expand(char[] aInput)
          Expand a 16 bit sequence into 32 bits.
static byte getHighByte(char aInput)
          Get high 8 bits of a character
static byte getLowByte(char aInput)
          Get low 8 bits of a character
static boolean hasHyphenRestrictions(int[] aCodePoints)
          The Unicode string MUST NOT contain "--" (two consecutive hyphens) in the third and fourth character positions and MUST NOT start or end with a "-" (hyphen).
static boolean isAscii(char aChar)
          Check if a character an ASCII character
static boolean isAscii(char[] aCharArray)
          Check if a character array is an ASCII array
static boolean isAscii(int aCodePoint)
          Check if an int is an ASCII character
static boolean isAscii(int[] aCodePoints)
          Check if an int array is an ASCII array
static boolean isDnsCompatible(char aChar)
          Check if the input character is DNS compatible.
static boolean isDnsCompatible(char[] aCharArray)
          Check if all characters in an input array are all DNS compatible.
static boolean isDnsCompatible(int aCodePoint)
          Check if the input codepoint is DNS compatible.
static boolean isDnsCompatible(int[] aCodePoints)
          Check if all ints in an input array are all DNS compatible.
static boolean isHighSurrogate(char aInput)
          Check a character is a high surrogate character
static boolean isLowSurrogate(char aInput)
          Check a character is a low surrogate character
static boolean isNative(char aChar)
          Check if a character could be part of a native encoding.
static boolean isNative(char[] aCharArray)
          Check if a character array could be a native encoding.
static boolean isPrintable(char aChar)
          Check if an input character is printable (c > 0x1f && c < 0x7f) || (c > 0xA0 && c < 0x100)
static boolean isPrintable(char[] aCharArray)
          Check if all characters in an input array are printable.
static boolean isPrintable(int aCodePoint)
          Check if an input integer is printable (c > 0x1f && c < 0x7f) || (c > 0xA0 && c < 0x100)
static boolean isPrintable(int[] aCodePoints)
          Check if all integers in an input array are printable.
static boolean isStd3Ascii(char[] aCharArray)
          Check if an input character is standard 3 ASCII character, required by IDNA.toAscii step #3
static boolean isStd3Ascii(int[] aCodePoints)
          Check if an input int is standard 3 ASCII int, required by IDNA.toAscii step #3
static boolean isSurrogate(char aInput)
          Check a character is a surrogate character
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HYPHEN

public static final char HYPHEN
Constants

See Also:
Constant Field Values
Constructor Detail

Utf16

public Utf16()
Method Detail

contract

public static byte[] contract(char[] aInput)
Contract a 16 bit sequence into 8 bits.
Used when retrieving a native encoding from a String object.
example: abcd, efgh, -> cd, gh

Parameters:
aInput - A char array
Returns:
output A byte array matching low bytes of the input.

contract

public static char[] contract(int[] aInput)
Contract a 32 bit sequence into 16 bits.
Used when the input to Ace.encode() does not require encoding.
example: abcdefgh, jklmnopq -> efgh, nopq

Parameters:
aInput - An integer array
Returns:
output A char array matching low chars of the input

expand

public static char[] expand(byte[] aInput)
Expand a 8 bit sequence into 16 bits.
Used to create a String object from a native encoding.
example: ab, cd, -> 00ab, 00cd

Parameters:
aInput - A byte array
Returns:
output A char array matching low bytes of the input

expand

public static int[] expand(char[] aInput)
Expand a 16 bit sequence into 32 bits.
Used when the input to Ace.decode does not have a prefix.
Also used in Idna.toUnicode() on any Exception, to return the input.
example: abcd, efgh -> 0000abcd, 0000efgh

Parameters:
aInput - A char array
Returns:
output An integer array matching low chars of the input

getHighByte

public static byte getHighByte(char aInput)
Get high 8 bits of a character

Parameters:
aInput - a character

getLowByte

public static byte getLowByte(char aInput)
Get low 8 bits of a character

Parameters:
aInput - a character

isAscii

public static boolean isAscii(char aChar)
Check if a character an ASCII character

Parameters:
aChar - a character
Returns:
true if the character is an ASCII character, otherwise false

isAscii

public static boolean isAscii(char[] aCharArray)
Check if a character array is an ASCII array

Parameters:
aCharArray - a character array
Returns:
true if all characters in the array are ASCII character, otherwise false.

isAscii

public static boolean isAscii(int aCodePoint)
Check if an int is an ASCII character

Parameters:
aCodePoint - an int
Returns:
true if the int is a ASCII character, otherwise false.

isAscii

public static boolean isAscii(int[] aCodePoints)
Check if an int array is an ASCII array

Parameters:
aCodePoints - an int array
Returns:
true if all ints in the array are ASCII character, otherwise false.

isDnsCompatible

public static boolean isDnsCompatible(char aChar)
Check if the input character is DNS compatible. This method returns true if the input character is a letter, digit, or hyphen.

Parameters:
aChar - a character
Returns:
true if the character is DNS compatible, otherwise false

isDnsCompatible

public static boolean isDnsCompatible(char[] aCharArray)
Check if all characters in an input array are all DNS compatible. Ace uses this to determine if a label must be encoded

Parameters:
aCharArray - character array
Returns:
true if and only if all characters in the array are DNS compatible

isDnsCompatible

public static boolean isDnsCompatible(int aCodePoint)
Check if the input codepoint is DNS compatible. This method returns true if the input character is a letter, digit, or hyphen.

Parameters:
aCodePoint - an integer
Returns:
true if the codepoint is DNS compatible, otherwise false

isDnsCompatible

public static boolean isDnsCompatible(int[] aCodePoints)
Check if all ints in an input array are all DNS compatible. Ace uses this to determine if a label must be encoded

Parameters:
aCodePoints - a int array
Returns:
true if all ints in the array are DNS compatible, otherwise false

isHighSurrogate

public static boolean isHighSurrogate(char aInput)
Check a character is a high surrogate character

Parameters:
aInput - a character to be checked

isLowSurrogate

public static boolean isLowSurrogate(char aInput)
Check a character is a low surrogate character

Parameters:
aInput - a character to be checked

isNative

public static boolean isNative(char aChar)
Check if a character could be part of a native encoding.

Parameters:
aChar - a character
Returns:
true if the high byte is 0x00, false otherwise

isNative

public static boolean isNative(char[] aCharArray)
Check if a character array could be a native encoding.

Parameters:
aCharArray - a character array
Returns:
true if all high bytes are 0x00, false otherwise

isPrintable

public static boolean isPrintable(char aChar)
Check if an input character is printable (c > 0x1f && c < 0x7f) || (c > 0xA0 && c < 0x100)

Parameters:
aChar - a character
Returns:
true if the character is printable, false otherwise

isPrintable

public static boolean isPrintable(char[] aCharArray)
Check if all characters in an input array are printable.

Parameters:
aCharArray - character array
Returns:
true if all characters in the array are printable, false otherwise

isPrintable

public static boolean isPrintable(int aCodePoint)
Check if an input integer is printable (c > 0x1f && c < 0x7f) || (c > 0xA0 && c < 0x100)

Parameters:
aCodePoint - an integer
Returns:
true if the integer is printable, false otherwise

isPrintable

public static boolean isPrintable(int[] aCodePoints)
Check if all integers in an input array are printable.

Parameters:
aCodePoints - integer array
Returns:
true if all integers in the array are printable, false otherwise

isStd3Ascii

public static boolean isStd3Ascii(char[] aCharArray)
Check if an input character is standard 3 ASCII character, required by IDNA.toAscii step #3

Parameters:
aCharArray - a character array
Returns:
true if the characters are all standard 3 ASCII character, otherwise false

isStd3Ascii

public static boolean isStd3Ascii(int[] aCodePoints)
Check if an input int is standard 3 ASCII int, required by IDNA.toAscii step #3

Parameters:
aCodePoints - an int
Returns:
true if the int is standard 3 ASCII character, otherwise false

hasHyphenRestrictions

public static boolean hasHyphenRestrictions(int[] aCodePoints)
The Unicode string MUST NOT contain "--" (two consecutive hyphens) in the third and fourth character positions and MUST NOT start or end with a "-" (hyphen).

Parameters:
aCodePoints - int array to check for hyphen restrictions
Returns:
true if the code points contain hyphens in first/last or 3rd/4th position.

isSurrogate

public static boolean isSurrogate(char aInput)
Check a character is a surrogate character

Parameters:
aInput - a character to be checked


Copyright © 2000-2010 VeriSign Inc. All Rights Reserved