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

pack-priv Class TransliteratorIDParser

extends Object
Class Inheritance
Imports
java.text.ParsePosition, java.util.ArrayList, .Collections, .HashMap, .List, .Map, com.ibm.icu.impl.PatternProps, .Utility, com.ibm.icu.util.CaseInsensitiveString

Parsing component for transliterator IDs. This class contains only static members; it cannot be instantiated. Methods in this class parse various ID formats, including the following: A basic ID, which contains source, target, and variant, but no filter and no explicit inverse. Examples include "Latin-Greek/UNGEGN" and "Null". A single ID, which is a basic ID plus optional filter and optional explicit inverse. Examples include "[a-zA-Z] Latin-Greek" and "Lower (Upper)". A compound ID, which is a sequence of one or more single IDs, separated by semicolons, with optional forward and reverse global filters. The global filters are UnicodeSet patterns prepended or appended to the IDs, separated by semicolons. An appended filter must be enclosed in parentheses and applies in the reverse direction.
Author
Alan Liu

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
TransliteratorIDParser.SingleID

A structure containing the canonicalized data of a filtered ID, that is, a basic ID optionally with a filter.

private static class
TransliteratorIDParser.Specs

A structure containing the parsed data of a filtered ID, that is, a basic ID optionally with a filter.

Field Summary

Modifier and TypeField and Description
private static final String
private static final char
private static final int
private static final char
private static final char
private static final int
private static final Map<CaseInsensitiveString, String>
private static final char
private static final char

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static String[]

Returns:

an array of 4 strings: source, target, variant, and isSourcePresent. If the source is not present, ANY will be given as the source, and isSourcePresent will be null. Otherwise isSourcePresent will be non-null. The target may be empty if the id is not well-formed. The variant may be empty.
IDtoSTV
(String
the id string, in any of several forms
id
)

Parse an ID into pieces.

pack-priv static List<Transliterator>

Returns:

Actual transliterators for the list of SingleIDs
instantiateList
(List<TransliteratorIDParser.SingleID>
list vector of SingleID objects.
ids
)

Returns the list of Transliterator objects for the given list of SingleID objects.

public static boolean

Returns:

true if the parse succeeds, that is, if the entire id is consumed without syntax error.
parseCompoundID
(String
the pattern the parse
id
,
int
the direction.
dir
,
StringBuffer
OUTPUT parameter that receives the canonical ID, consisting of canonical IDs for all elements, as returned by parseSingleID(), separated by semicolons. Previous contents are discarded.
canonID
,
List<TransliteratorIDParser.SingleID>
OUTPUT parameter that receives a list of SingleID objects representing the parsed IDs. Previous contents are discarded.
list
,
UnicodeSet[]
OUTPUT parameter that receives a pointer to a newly created global filter for this ID in this direction, or null if there is none.
globalFilter
)

Parse a compound ID, consisting of an optional forward global filter, a separator, one or more single IDs delimited by separators, an an optional reverse global filter.

public static TransliteratorIDParser.SingleID

Returns:

a SingleID object or null if the parse fails
parseFilterID
(String
the id to be parsed
id
,
int[]
INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.
pos
)

Parse a filter ID, that is, an ID of the general form "[f1] s1-t1/v1", with the filters optional, and the variants optional.

private static TransliteratorIDParser.Specs

Returns:

a Specs object, or null if the parse failed. If neither source nor target was seen in the parsed id, then the parse fails. If allowFilter is true, then the parsed filter pattern is returned in the Specs object, otherwise the returned filter reference is null. If the parse fails for any reason null is returned.
parseFilterID
(String
the id string, in any of several forms
id
,
int[]
INPUT-OUTPUT parameter. On input, pos[0] is the offset of the first character to parse in id. On output, pos[0] is the offset after the last parsed character. If the parse failed, pos[0] will be unchanged.
pos
,
boolean
if true, a UnicodeSet pattern is allowed at any location between specs or delimiters, and is returned as the fifth string in the array.
allowFilter
)

Parse an ID into component pieces.

public static UnicodeSet

Returns:

a UnicodeSet object or null. A non-null results indicates a successful parse, regardless of whether the filter applies to the given direction. The caller should discard it if withParens != (dir == REVERSE).
parseGlobalFilter
(String
the pattern the parse
id
,
int[]
INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.
pos
,
int
the direction.
dir
,
int[]
INPUT-OUTPUT parameter. On entry, if withParens[0] is 0, then parens are disallowed. If it is 1, then parens are requires. If it is -1, then parens are optional, and the return result will be set to 0 or 1.
withParens
,
StringBuffer
OUTPUT parameter. The pattern for the filter added to the canonID, either at the end, if dir is FORWARD, or at the start, if dir is REVERSE. The pattern will be enclosed in parentheses if appropriate, and will be suffixed with an ID_DELIM character. May be null.
canonID
)

Parse a global filter of the form "[f]" or "([f])", depending on 'withParens'.

public static TransliteratorIDParser.SingleID

Returns:

a SingleID object or null
parseSingleID
(String
the id to be parsed
id
,
int[]
INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.
pos
,
int
the direction. If the direction is REVERSE then the SingleID is constructed for the reverse direction.
dir
)

Parse a single ID, that is, an ID of the general form "[f1] s1-t1/v1 ([f2] s2-t3/v2)", with the parenthesized element optional, the filters optional, and the variants optional.

public static void
registerSpecialInverse(String
the target against which to register the inverse
target
,
String
the inverse of target, that is Any-target.getInverse() => Any-inverseTarget
inverseTarget
,
boolean
if true, register the reverse relation as well, that is, Any-inverseTarget.getInverse() => Any-target
bidirectional
)

Register two targets as being inverses of one another.

private static TransliteratorIDParser.SingleID

Returns:

a SingleID; never returns null. Returned object always has 'filter' field of null.
specsToID
(TransliteratorIDParser.Specs specs, int dir)

Givens a Spec object, convert it to a SingleID object.

private static TransliteratorIDParser.SingleID

Returns:

a SingleID or null. Returned object always has 'filter' field of null.
specsToSpecialInverse
(TransliteratorIDParser.Specs specs)

Given a Specs object, return a SingleID representing the special inverse of that ID. If there is no special inverse then return null.

public static String
STVtoID(String source, String target, String variant)

Given source, target, and variant strings, concatenate them into a full ID. If the source is empty, then "Any" will be used for the source, so the ID will always be of the form s-t/v or s-t.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANYback to summary
private static final String ANY
CLOSE_REVback to summary
private static final char CLOSE_REV
FORWARDback to summary
private static final int FORWARD
ID_DELIMback to summary
private static final char ID_DELIM
OPEN_REVback to summary
private static final char OPEN_REV
REVERSEback to summary
private static final int REVERSE
SPECIAL_INVERSESback to summary
private static final Map<CaseInsensitiveString, String> SPECIAL_INVERSES
TARGET_SEPback to summary
private static final char TARGET_SEP
VARIANT_SEPback to summary
private static final char VARIANT_SEP

Constructor Detail

TransliteratorIDParserback to summary
pack-priv TransliteratorIDParser()

Method Detail

IDtoSTVback to summary
public static String[] IDtoSTV(String id)

Parse an ID into pieces. Take IDs of the form T, T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a source of ANY.

Parameters
id:String

the id string, in any of several forms

Returns:String[]

an array of 4 strings: source, target, variant, and isSourcePresent. If the source is not present, ANY will be given as the source, and isSourcePresent will be null. Otherwise isSourcePresent will be non-null. The target may be empty if the id is not well-formed. The variant may be empty.

instantiateListback to summary
pack-priv static List<Transliterator> instantiateList(List<TransliteratorIDParser.SingleID> ids)

Returns the list of Transliterator objects for the given list of SingleID objects.

Parameters
ids:List<TransliteratorIDParser.SingleID>

list vector of SingleID objects.

Returns:List<Transliterator>

Actual transliterators for the list of SingleIDs

parseCompoundIDback to summary
public static boolean parseCompoundID(String id, int dir, StringBuffer canonID, List<TransliteratorIDParser.SingleID> list, UnicodeSet[] globalFilter)

Parse a compound ID, consisting of an optional forward global filter, a separator, one or more single IDs delimited by separators, an an optional reverse global filter. The separator is a semicolon. The global filters are UnicodeSet patterns. The reverse global filter must be enclosed in parentheses.

Parameters
id:String

the pattern the parse

dir:int

the direction.

canonID:StringBuffer

OUTPUT parameter that receives the canonical ID, consisting of canonical IDs for all elements, as returned by parseSingleID(), separated by semicolons. Previous contents are discarded.

list:List<TransliteratorIDParser.SingleID>

OUTPUT parameter that receives a list of SingleID objects representing the parsed IDs. Previous contents are discarded.

globalFilter:UnicodeSet[]

OUTPUT parameter that receives a pointer to a newly created global filter for this ID in this direction, or null if there is none.

Returns:boolean

true if the parse succeeds, that is, if the entire id is consumed without syntax error.

parseFilterIDback to summary
public static TransliteratorIDParser.SingleID parseFilterID(String id, int[] pos)

Parse a filter ID, that is, an ID of the general form "[f1] s1-t1/v1", with the filters optional, and the variants optional.

Parameters
id:String

the id to be parsed

pos:int[]

INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.

Returns:TransliteratorIDParser.SingleID

a SingleID object or null if the parse fails

parseFilterIDback to summary
private static TransliteratorIDParser.Specs parseFilterID(String id, int[] pos, boolean allowFilter)

Parse an ID into component pieces. Take IDs of the form T, T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a source of ANY.

Parameters
id:String

the id string, in any of several forms

pos:int[]

INPUT-OUTPUT parameter. On input, pos[0] is the offset of the first character to parse in id. On output, pos[0] is the offset after the last parsed character. If the parse failed, pos[0] will be unchanged.

allowFilter:boolean

if true, a UnicodeSet pattern is allowed at any location between specs or delimiters, and is returned as the fifth string in the array.

Returns:TransliteratorIDParser.Specs

a Specs object, or null if the parse failed. If neither source nor target was seen in the parsed id, then the parse fails. If allowFilter is true, then the parsed filter pattern is returned in the Specs object, otherwise the returned filter reference is null. If the parse fails for any reason null is returned.

parseGlobalFilterback to summary
public static UnicodeSet parseGlobalFilter(String id, int[] pos, int dir, int[] withParens, StringBuffer canonID)

Parse a global filter of the form "[f]" or "([f])", depending on 'withParens'.

Parameters
id:String

the pattern the parse

pos:int[]

INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.

dir:int

the direction.

withParens:int[]

INPUT-OUTPUT parameter. On entry, if withParens[0] is 0, then parens are disallowed. If it is 1, then parens are requires. If it is -1, then parens are optional, and the return result will be set to 0 or 1.

canonID:StringBuffer

OUTPUT parameter. The pattern for the filter added to the canonID, either at the end, if dir is FORWARD, or at the start, if dir is REVERSE. The pattern will be enclosed in parentheses if appropriate, and will be suffixed with an ID_DELIM character. May be null.

Returns:UnicodeSet

a UnicodeSet object or null. A non-null results indicates a successful parse, regardless of whether the filter applies to the given direction. The caller should discard it if withParens != (dir == REVERSE).

parseSingleIDback to summary
public static TransliteratorIDParser.SingleID parseSingleID(String id, int[] pos, int dir)

Parse a single ID, that is, an ID of the general form "[f1] s1-t1/v1 ([f2] s2-t3/v2)", with the parenthesized element optional, the filters optional, and the variants optional.

Parameters
id:String

the id to be parsed

pos:int[]

INPUT-OUTPUT parameter. On input, the position of the first character to parse. On output, the position after the last character parsed.

dir:int

the direction. If the direction is REVERSE then the SingleID is constructed for the reverse direction.

Returns:TransliteratorIDParser.SingleID

a SingleID object or null

registerSpecialInverseback to summary
public static void registerSpecialInverse(String target, String inverseTarget, boolean bidirectional)

Register two targets as being inverses of one another. For example, calling registerSpecialInverse("NFC", "NFD", true) causes Transliterator to form the following inverse relationships:

NFC => NFD
Any-NFC => Any-NFD
NFD => NFC
Any-NFD => Any-NFC
(Without the special inverse registration, the inverse of NFC would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but that the presence or absence of "Any-" is preserved.

The relationship is symmetrical; registering (a, b) is equivalent to registering (b, a).

The relevant IDs must still be registered separately as factories or classes.

Only the targets are specified. Special inverses always have the form Any-Target1 <=> Any-Target2. The target should have canonical casing (the casing desired to be produced when an inverse is formed) and should contain no whitespace or other extraneous characters.

Parameters
target:String

the target against which to register the inverse

inverseTarget:String

the inverse of target, that is Any-target.getInverse() => Any-inverseTarget

bidirectional:boolean

if true, register the reverse relation as well, that is, Any-inverseTarget.getInverse() => Any-target

specsToIDback to summary
private static TransliteratorIDParser.SingleID specsToID(TransliteratorIDParser.Specs specs, int dir)

Givens a Spec object, convert it to a SingleID object. The Spec object is a more unprocessed parse result. The SingleID object contains information about canonical and basic IDs.

Returns:TransliteratorIDParser.SingleID

a SingleID; never returns null. Returned object always has 'filter' field of null.

specsToSpecialInverseback to summary
private static TransliteratorIDParser.SingleID specsToSpecialInverse(TransliteratorIDParser.Specs specs)

Given a Specs object, return a SingleID representing the special inverse of that ID. If there is no special inverse then return null.

Returns:TransliteratorIDParser.SingleID

a SingleID or null. Returned object always has 'filter' field of null.

STVtoIDback to summary
public static String STVtoID(String source, String target, String variant)

Given source, target, and variant strings, concatenate them into a full ID. If the source is empty, then "Any" will be used for the source, so the ID will always be of the form s-t/v or s-t.

com.ibm.icu.text back to summary

pack-priv Class TransliteratorIDParser.SingleID

extends Object
Class Inheritance

A structure containing the canonicalized data of a filtered ID, that is, a basic ID optionally with a filter. 'canonID' is always non-null. It may be the empty string "". It is the id that should be assigned to the created transliterator. It _cannot_ be instantiated directly. 'basicID' is always non-null and non-empty. It is always of the form S-T or S-T/V. It is designed to be fed to low-level instantiation code that only understands these two formats. 'filter' may be null, if there is none, or non-null and non-empty.

Field Summary

Modifier and TypeField and Description
public String
public String
public String

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Transliterator
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

basicIDback to summary
public String basicID
canonIDback to summary
public String canonID
filterback to summary
public String filter

Constructor Detail

SingleIDback to summary
pack-priv SingleID(String c, String b, String f)
SingleIDback to summary
pack-priv SingleID(String c, String b)

Method Detail

getInstanceback to summary
pack-priv Transliterator getInstance()
com.ibm.icu.text back to summary

private Class TransliteratorIDParser.Specs

extends Object
Class Inheritance

A structure containing the parsed data of a filtered ID, that is, a basic ID optionally with a filter. 'source' and 'target' will always be non-null. The 'variant' will be non-null only if a non-empty variant was parsed. 'sawSource' is true if there was an explicit source in the parsed id. If there was no explicit source, then an implied source of ANY is returned and 'sawSource' is set to false. 'filter' is the parsed filter pattern, or null if there was no filter.

Field Summary

Modifier and TypeField and Description
public String
public boolean
public String
public String
public String

Constructor Summary

AccessConstructor and Description
pack-priv
Specs(String s, String t, String v, boolean sawS, String f)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filterback to summary
public String filter
sawSourceback to summary
public boolean sawSource
sourceback to summary
public String source
targetback to summary
public String target
variantback to summary
public String variant

Constructor Detail

Specsback to summary
pack-priv Specs(String s, String t, String v, boolean sawS, String f)