Top Description Inners Fields Constructors Methods
com.ibm.icu.text

pack-priv Class AnyTransliterator

extends Transliterator
Class Inheritance
Imports
java.util.ArrayList, .Enumeration, .HashMap, .HashSet, .List, .MissingResourceException, .Set, java.util.concurrent.ConcurrentHashMap, com.ibm.icu.lang.UScript

A transliterator that translates multiple input scripts to a single output script. It is named Any-T or Any-T/V, where T is the target and V is the optional variant. The target T is a script.

An AnyTransliterator partitions text into runs of the same script, together with adjacent COMMON or INHERITED characters. After determining the script of each run, it transliterates from that script to the given target/variant. It does so by instantiating a transliterator from the source script to the target/variant. If a run consists only of the target script, COMMON, or INHERITED characters, then the run is not changed.

At startup, all possible AnyTransliterators are registered with the system, as determined by examining the registered script transliterators.

Author
Alan Liu
Since
ICU 2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AnyTransliterator.ScriptRunIterator

Returns a series of ranges corresponding to scripts.

private static class
AnyTransliterator.WidthFix

Lazily initialize a special Transliterator for handling width characters.

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private ConcurrentHashMap<Integer, Transliterator>
cache

Cache mapping UScriptCode values to Transliterator*.

pack-priv static final String
pack-priv static final String
private String
target

The target or target/variant string.

pack-priv static final char
private int
targetScript

The target script code.

pack-priv static final char
Inherited from com.ibm.icu.text.Transliterator:
DEBUGFORWARDID_DELIMID_SEPREVERSE

Constructor Summary

AccessConstructor and Description
private
AnyTransliterator(String
the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.
id
,
String
the target name. Must not be empty, and must name a script corresponding to theTargetScript.
theTarget
,
String
the variant name, or the empty string if there is no variant
theVariant
,
int
the script code corresponding to theTarget.
theTargetScript
)

Private constructor

public
AnyTransliterator(String
the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.
id
,
UnicodeFilter
The Unicode filter.
filter
,
String
the target name.
target2
,
int
the script code corresponding to theTarget.
targetScript2
,
Transliterator
Not used. This parameter is deprecated.
widthFix2
,
ConcurrentHashMap<Integer, Transliterator>
The Map object for cache.
cache2
)

Method Summary

Modifier and TypeMethod and Description
public void
addSourceTargetSet(UnicodeSet inputFilter, UnicodeSet sourceSet, UnicodeSet
TODO
targetSet
)

Overrides com.ibm.icu.text.Transliterator.addSourceTargetSet.

Returns the set of all characters that may be generated as replacement text by this transliterator, filtered by BOTH the input filter, and the current getFilter().
private Transliterator
getTransliterator(int source)

Returns a transliterator from the given source to our target or target/variant.

protected void
handleTransliterate(Replaceable
the buffer holding transliterated and untransliterated text
text
,
Transliterator.Position
the indices indicating the start, limit, context start, and context limit of the text.
pos
,
boolean
if true, assume more text may be inserted at pos.limit and act accordingly. Otherwise, transliterate all text between pos.start and pos.limit and move pos.start up to pos.limit.
isIncremental
)

Implements abstract com.ibm.icu.text.Transliterator.handleTransliterate.

Implements Transliterator#handleTransliterate.
private boolean
isWide(int script)

pack-priv static void
register()

Registers standard transliterators with the system.

public Transliterator
safeClone()

Temporary hack for registry problem.

private static int
scriptNameToCode(String name)

Return the script code for a given name, or UScript.INVALID_CODE if not found.

Inherited from com.ibm.icu.text.Transliterator:
baseToRulescreateFromRulesfilteredTransliteratefinishTransliterationgetAvailableIDsgetAvailableSourcesgetAvailableTargetsgetAvailableVariantsgetBasicInstancegetDisplayNamegetDisplayNamegetDisplayNamegetElementsgetFiltergetFilterAsUnicodeSetgetIDgetInstancegetInstancegetInversegetMaximumContextLengthgetSourceSetgetTargetSethandleGetSourceSetregisterAliasregisterAnyregisterClassregisterFactoryregisterInstanceregisterInstanceregisterSpecialInversesetFiltersetIDsetMaximumContextLengthtoRulestransformtransliteratetransliteratetransliteratetransliteratetransliteratetransliterateunregister

Field Detail

ANYback to summary
pack-priv static final String ANY
cacheback to summary
private ConcurrentHashMap<Integer, Transliterator> cache

Cache mapping UScriptCode values to Transliterator*.

LATIN_PIVOTback to summary
pack-priv static final String LATIN_PIVOT
NULL_IDback to summary
pack-priv static final String NULL_ID
targetback to summary
private String target

The target or target/variant string.

TARGET_SEPback to summary
pack-priv static final char TARGET_SEP
targetScriptback to summary
private int targetScript

The target script code. Never USCRIPT_INVALID_CODE.

VARIANT_SEPback to summary
pack-priv static final char VARIANT_SEP

Hides com.ibm.icu.text.Transliterator.VARIANT_SEP.

Constructor Detail

AnyTransliteratorback to summary
private AnyTransliterator(String id, String theTarget, String theVariant, int theTargetScript)

Private constructor

Parameters
id:String

the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.

theTarget:String

the target name. Must not be empty, and must name a script corresponding to theTargetScript.

theVariant:String

the variant name, or the empty string if there is no variant

theTargetScript:int

the script code corresponding to theTarget.

AnyTransliteratorback to summary
public AnyTransliterator(String id, UnicodeFilter filter, String target2, int targetScript2, Transliterator widthFix2, ConcurrentHashMap<Integer, Transliterator> cache2)
Parameters
id:String

the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.

filter:UnicodeFilter

The Unicode filter.

target2:String

the target name.

targetScript2:int

the script code corresponding to theTarget.

widthFix2:Transliterator

Not used. This parameter is deprecated.

cache2:ConcurrentHashMap<Integer, Transliterator>

The Map object for cache.

Method Detail

addSourceTargetSetback to summary
public void addSourceTargetSet(UnicodeSet inputFilter, UnicodeSet sourceSet, UnicodeSet targetSet)

Overrides com.ibm.icu.text.Transliterator.addSourceTargetSet.

Doc from com.ibm.icu.text.Transliterator.addSourceTargetSet.

Returns the set of all characters that may be generated as replacement text by this transliterator, filtered by BOTH the input filter, and the current getFilter().

SHOULD BE OVERRIDDEN BY SUBCLASSES. It is probably an error for any transliterator to NOT override this, but we can't force them to for backwards compatibility.

Other methods vector through this.

When gathering the information on source and target, the compound transliterator makes things complicated. For example, suppose we have:

Global FILTER = [ax]
a > b;
:: NULL;
b > c;
x > d;
While the filter just allows a and x, b is an intermediate result, which could produce c. So the source and target sets cannot be gathered independently. What we have to do is filter the sources for the first transliterator according to the global filter, intersect that transliterator's filter. Based on that we get the target. The next transliterator gets as a global filter (global + last target). And so on.

There is another complication:

Global FILTER = [ax]
a >|b;
b >c;
Even though b would be filtered from the input, whenever we have a backup, it could be part of the input. So ideally we will change the global filter as we go.
Parameters
targetSet:UnicodeSet

TODO

Annotations
@Override
getTransliteratorback to summary
private Transliterator getTransliterator(int source)

Returns a transliterator from the given source to our target or target/variant. Returns NULL if the source is the same as our target script, or if the source is USCRIPT_INVALID_CODE. Caches the result and returns the same transliterator the next time. The caller does NOT own the result and must not delete it.

handleTransliterateback to summary
protected void handleTransliterate(Replaceable text, Transliterator.Position pos, boolean isIncremental)

Implements abstract com.ibm.icu.text.Transliterator.handleTransliterate.

Implements Transliterator#handleTransliterate.

Parameters
text:Replaceable

Doc from com.ibm.icu.text.Transliterator.handleTransliterate.

the buffer holding transliterated and untransliterated text

pos:Transliterator.Position

Doc from com.ibm.icu.text.Transliterator.handleTransliterate.

the indices indicating the start, limit, context start, and context limit of the text.

isIncremental:boolean

Doc from com.ibm.icu.text.Transliterator.handleTransliterate.

if true, assume more text may be inserted at pos.limit and act accordingly. Otherwise, transliterate all text between pos.start and pos.limit and move pos.start up to pos.limit.

Annotations
@Override
isWideback to summary
private boolean isWide(int script)
registerback to summary
pack-priv static void register()

Registers standard transliterators with the system. Called by Transliterator during initialization. Scan all current targets and register those that are scripts T as Any-T/V.

safeCloneback to summary
public Transliterator safeClone()

Temporary hack for registry problem. Needs to be replaced by better architecture.

scriptNameToCodeback to summary
private static int scriptNameToCode(String name)

Return the script code for a given name, or UScript.INVALID_CODE if not found.

com.ibm.icu.text back to summary

private Class AnyTransliterator.ScriptRunIterator

extends Object
Class Inheritance

Returns a series of ranges corresponding to scripts. They will be of the form: ccccSScSSccccTTcTcccc - c = common, S = first script, T = second | | - first run (start, limit) | | - second run (start, limit) That is, the runs will overlap. The reason for this is so that a transliterator can consider common characters both before and after the scripts.

Field Summary

Modifier and TypeField and Description
public int
limit

The end of the run, exclusive, valid after next() returns.

public int
scriptCode

The code of the current run, valid after next() returns.

public int
start

The start of the run, inclusive, valid after next() returns.

private Replaceable
private int
private int

Constructor Summary

AccessConstructor and Description
public
ScriptRunIterator(Replaceable text, int start, int limit)

Constructs a run iterator over the given text from start (inclusive) to limit (exclusive).

Method Summary

Modifier and TypeMethod and Description
public void
adjustLimit(int delta)

Adjusts internal indices for a change in the limit index of the given delta.

public boolean
next()

Returns true if there are any more runs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

limitback to summary
public int limit

The end of the run, exclusive, valid after next() returns.

scriptCodeback to summary
public int scriptCode

The code of the current run, valid after next() returns. May be UScript.INVALID_CODE if and only if the entire text is COMMON/INHERITED.

startback to summary
public int start

The start of the run, inclusive, valid after next() returns.

textback to summary
private Replaceable text
textLimitback to summary
private int textLimit
textStartback to summary
private int textStart

Constructor Detail

ScriptRunIteratorback to summary
public ScriptRunIterator(Replaceable text, int start, int limit)

Constructs a run iterator over the given text from start (inclusive) to limit (exclusive).

Method Detail

adjustLimitback to summary
public void adjustLimit(int delta)

Adjusts internal indices for a change in the limit index of the given delta. A positive delta means the limit has increased.

nextback to summary
public boolean next()

Returns true if there are any more runs. true is always returned at least once. Upon return, the caller should examine scriptCode, start, and limit.

com.ibm.icu.text back to summary

private Class AnyTransliterator.WidthFix

extends Object
Class Inheritance

Lazily initialize a special Transliterator for handling width characters.

Field Summary

Modifier and TypeField and Description
private static final String
pack-priv static final Transliterator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

IDback to summary
private static final String ID
INSTANCEback to summary
pack-priv static final Transliterator INSTANCE

Constructor Detail

WidthFixback to summary
private WidthFix()