com.ibm.text
Class UnicodeToHexTransliterator

java.lang.Object
  |
  +--com.ibm.text.Transliterator
        |
        +--com.ibm.text.UnicodeToHexTransliterator

public class UnicodeToHexTransliterator
extends Transliterator

A transliterator that converts from Unicode characters to hexadecimal Unicode escape sequences. It outputs a prefix specified in the constructor and optionally converts the hex digits to uppercase.

The format of the output is set by a pattern. This pattern follows the same syntax as HexToUnicodeTransliterator, except it does not allow multiple specifications. The pattern sets the prefix string, suffix string, and minimum and maximum digit count. There are no setters or getters for these attributes; they are set only through the pattern.

The setUppercase() and isUppercase() methods control whether 'a' through 'f' or 'A' through 'F' are output as hex digits. This is not controlled through the pattern; only through the methods. The default is uppercase.

Version:
$RCSfile: UnicodeToHexTransliterator.java,v $ $Revision: 1.11 $ $Date: 2001/09/28 20:23:42 $
Author:
Alan Liu

Inner classes inherited from class com.ibm.text.Transliterator
Transliterator.Factory, Transliterator.Position
 
Fields inherited from class com.ibm.text.Transliterator
FORWARD, ID_DELIM, ID_SEP, REVERSE, VARIANT_SEP
 
Constructor Summary
UnicodeToHexTransliterator()
          Constructs a transliterator with the default prefix "\u" that outputs four uppercase hex digits.
UnicodeToHexTransliterator(java.lang.String pattern)
          Constructs an uppercase transliterator with no filter.
UnicodeToHexTransliterator(java.lang.String pattern, boolean uppercase, UnicodeFilter filter)
          Constructs a transliterator.
 
Method Summary
 void applyPattern(java.lang.String thePattern)
          Set the pattern recognized by this transliterator.
 java.lang.String getPrefix()
          Returns the string that precedes the four hex digits.
protected  void handleTransliterate(Replaceable text, Transliterator.Position offsets, boolean incremental)
          Implements Transliterator.handleTransliterate(com.ibm.text.Replaceable, com.ibm.text.Transliterator.Position, boolean).
 boolean isUppercase()
          Returns true if this transliterator outputs uppercase hex digits.
 void setPrefix(java.lang.String prefix)
          Sets the string that precedes the four hex digits.
 void setUppercase(boolean outputUppercase)
          Sets if this transliterator outputs uppercase hex digits.
 java.lang.String toPattern()
          Return this transliterator's pattern.
 
Methods inherited from class com.ibm.text.Transliterator
baseToRules, createFromRules, filteredCharAt, filteredTransliterate, finishTransliteration, getAvailableIDs, getAvailableSources, getAvailableTargets, getAvailableVariants, getDisplayName, getDisplayName, getFilter, getID, getInstance, getInstance, getInverse, getMaximumContextLength, registerClass, registerFactory, setFilter, setID, setMaximumContextLength, toRules, transliterate, transliterate, transliterate, transliterate, transliterate, transliterate, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnicodeToHexTransliterator

public UnicodeToHexTransliterator(java.lang.String pattern,
                                  boolean uppercase,
                                  UnicodeFilter filter)
Constructs a transliterator.
Parameters:
pattern - The pattern for this transliterator. See applyPattern() for pattern syntax.
uppercase - if true, the four hex digits will be converted to uppercase; otherwise they will be lowercase. Ignored if direction is HEX_UNICODE.
filter - the filter for this transliterator, or null if none.

UnicodeToHexTransliterator

public UnicodeToHexTransliterator(java.lang.String pattern)
Constructs an uppercase transliterator with no filter.
Parameters:
pattern - The pattern for this transliterator. See applyPattern() for pattern syntax.

UnicodeToHexTransliterator

public UnicodeToHexTransliterator()
Constructs a transliterator with the default prefix "\u" that outputs four uppercase hex digits.
Method Detail

applyPattern

public void applyPattern(java.lang.String thePattern)
Set the pattern recognized by this transliterator. The pattern must contain zero or more prefix characters, one or more digit characters, and zero or more suffix characters. The digit characters indicates optional digits ('#') followed by required digits ('0'). The total number of digits cannot exceed 4, and must be at least 1 required digit. Use a backslash ('\\') to escape any of the special characters. An empty pattern is not allowed.

Example: "U+0000" specifies a prefix of "U+", exactly four digits, and no suffix. "<###0>" has a prefix of "<", between one and four digits, and a suffix of ">".

 pattern := prefix-char* digit-spec suffix-char*
 digit-spec := '#'* '0'+
 prefix-char := [^special-char] | '\\' special-char
 suffix-char := [^special-char] | '\\' special-char
 special-char := ';' | '0' | '#' | '\\'
 

Limitations: There is no way to set the uppercase attribute in the pattern. (applyPattern() does not alter the uppercase attribute.)


toPattern

public java.lang.String toPattern()
Return this transliterator's pattern.

getPrefix

public java.lang.String getPrefix()
Returns the string that precedes the four hex digits.
Returns:
prefix string

setPrefix

public void setPrefix(java.lang.String prefix)
Sets the string that precedes the four hex digits.

Callers must take care if a transliterator is in use by multiple threads. The prefix should not be changed by one thread while another thread may be transliterating.

Parameters:
prefix - prefix string

isUppercase

public boolean isUppercase()
Returns true if this transliterator outputs uppercase hex digits.

setUppercase

public void setUppercase(boolean outputUppercase)
Sets if this transliterator outputs uppercase hex digits.

Callers must take care if a transliterator is in use by multiple threads. The uppercase mode should not be changed by one thread while another thread may be transliterating.

Parameters:
outputUppercase - if true, then this transliterator outputs uppercase hex digits.

handleTransliterate

protected void handleTransliterate(Replaceable text,
                                   Transliterator.Position offsets,
                                   boolean incremental)
Implements Transliterator.handleTransliterate(com.ibm.text.Replaceable, com.ibm.text.Transliterator.Position, boolean).
Overrides:
handleTransliterate in class Transliterator
Following copied from class: com.ibm.text.Transliterator
Parameters:
text - the buffer holding transliterated and untransliterated text
pos - the start and limit of the text, the position of the cursor, and the start and limit of transliteration.
incremental - if true, assume more text may be coming after pos.contextLimit. Otherwise, assume the text is complete.
See Also:
Transliterator.transliterate(com.ibm.text.Replaceable, int, int)


Copyright (c) 2001 IBM Corporation and others.