The primary functions are to produce a normalized string and to detect whether a string is already normalized. The most commonly used normalization forms are those defined in Unicode Standard Annex #15: Unicode Normalization Forms. However, this API supports additional normalization forms for specialized purposes. For example, NFKC_Casefold is provided via getInstance("nfkc_cf", COMPOSE) and can be used in implementations of UTS #46.
Not only are the standard compose and decompose modes supplied, but additional modes are provided as documented in the Mode enum.
Some of the functions in this class identify normalization boundaries. At a normalization boundary, the portions of the string before it and starting from it do not interact and can be handled independently.
The spanQuickCheckYes() stops at a normalization boundary. When the goal is a normalized string, then the text before the boundary can be copied, and the remainder can be processed with normalizeSecondAndAppend().
The hasBoundaryBefore(), hasBoundaryAfter() and isInert() functions test whether a character is guaranteed to be at a normalization boundary, regardless of context. This is used for moving from one normalization boundary to the next or preceding boundary, and for performing iterative normalization.
Iterative normalization is useful when only a small portion of a longer string needs to be processed. For example, in ICU, iterative normalization is used by the NormalizationTransliterator (to avoid replacing already-normalized text) and ucol_nextSortKeyPart() (to process only the substring for which sort key bytes are computed).
The set of normalization boundaries returned by these functions may not be complete: There may be more boundaries that could be returned. Different functions may return different boundaries.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public abstract StringBuilder | Returns: firststring, should be normalized first, CharSequence string, should be normalized second)Appends the second string to the first string (merging them at the boundary) and returns the first string. |
| public int | |
| public abstract String | Returns: c's decomposition mapping, if any; otherwise nullcode point c)Gets the decomposition mapping of c. |
| public static Normalizer2 | Returns: the requested Normalizer2, if successfulReturns a Normalizer2 instance for Unicode NFC normalization. |
| public static Normalizer2 | Returns: the requested Normalizer2, if successfulReturns a Normalizer2 instance for Unicode NFD normalization. |
| public static Normalizer2 | Returns: the requested Normalizer2, if successfulReturns a Normalizer2 instance for Unicode NFKC normalization. |
| public static Normalizer2 | Returns: the requested Normalizer2, if successfulReturns a Normalizer2 instance for Unicode NFKD normalization. |
| public abstract boolean | Returns: true if c has a normalization boundary before itcharacter to test c)Tests if the character always has a normalization boundary before it, regardless of context. |
| public abstract boolean | Returns: true if s is normalizedinput string s)Tests if the string is normalized. |
| public String | Returns: normalized srcsource string src)Returns the normalized form of the source string. |
| public abstract StringBuilder | Returns: destsource string src, StringBuilder destination string; its contents is replaced with normalized src dest)Writes the normalized form of the source string to the destination string (replacing its contents) and returns the destination string. |
| public abstract Appendable | Returns: destsource string src, Appendable destination Appendable; gets normalized src appended dest)Writes the normalized form of the source string to the destination Appendable and returns the destination Appendable. |
| public abstract StringBuilder | Returns: firststring, should be normalized first, CharSequence string, will be normalized second)Appends the normalized form of the second string to the first string (merging them at the boundary) and returns the first string. |
| public abstract int | Returns: "yes" span end indexinput string s)Returns the end of the normalized substring of the input string. |
| Normalizer2 | back to summary |
|---|---|
| protected Normalizer2() Sole constructor. (For invocation by subclass constructors, typically implicit.) | |
| append | back to summary |
|---|---|
| public abstract StringBuilder append(StringBuilder first, CharSequence second) Appends the second string to the first string (merging them at the boundary) and returns the first string. The result is normalized if both the strings were normalized. The first and second strings must be different objects.
| |
| getCombiningClass | back to summary |
|---|---|
| public int getCombiningClass(int c) Gets the combining class of c. The default implementation returns 0 but all standard implementations return the Unicode Canonical_Combining_Class value.
| |
| getDecomposition | back to summary |
|---|---|
| public abstract String getDecomposition(int c) Gets the decomposition mapping of c. Roughly equivalent to normalizing the String form of c on a DECOMPOSE Normalizer2 instance, but much faster, and except that this function returns null if c does not have a decomposition mapping in this instance's data. This function is independent of the mode of the Normalizer2. | |
| getNFCInstance | back to summary |
|---|---|
| public static Normalizer2 getNFCInstance() Returns a Normalizer2 instance for Unicode NFC normalization. Same as getInstance(null, "nfc", Mode.COMPOSE). Returns an unmodifiable singleton instance.
| |
| getNFDInstance | back to summary |
|---|---|
| public static Normalizer2 getNFDInstance() Returns a Normalizer2 instance for Unicode NFD normalization. Same as getInstance(null, "nfc", Mode.DECOMPOSE). Returns an unmodifiable singleton instance.
| |
| getNFKCInstance | back to summary |
|---|---|
| public static Normalizer2 getNFKCInstance() Returns a Normalizer2 instance for Unicode NFKC normalization. Same as getInstance(null, "nfkc", Mode.COMPOSE). Returns an unmodifiable singleton instance.
| |
| getNFKDInstance | back to summary |
|---|---|
| public static Normalizer2 getNFKDInstance() Returns a Normalizer2 instance for Unicode NFKD normalization. Same as getInstance(null, "nfkc", Mode.DECOMPOSE). Returns an unmodifiable singleton instance.
| |
| hasBoundaryBefore | back to summary |
|---|---|
| public abstract boolean hasBoundaryBefore(int c) Tests if the character always has a normalization boundary before it, regardless of context. If true, then the character does not normalization-interact with preceding characters. In other words, a string containing this character can be normalized by processing portions before this character and starting from this character independently. This is used for iterative normalization. See the class documentation for details.
| |
| isNormalized | back to summary |
|---|---|
| public abstract boolean isNormalized(CharSequence s) Tests if the string is normalized. Internally, in cases where the quickCheck() method would return "maybe" (which is only possible for the two COMPOSE modes) this method resolves to "yes" or "no" to provide a definitive result, at the cost of doing more work in those cases.
| |
| normalize | back to summary |
|---|---|
| public String normalize(CharSequence src) Returns the normalized form of the source string.
| |
| normalize | back to summary |
|---|---|
| public abstract StringBuilder normalize(CharSequence src, StringBuilder dest) Writes the normalized form of the source string to the destination string (replacing its contents) and returns the destination string. The source and destination strings must be different objects.
| |
| normalize | back to summary |
|---|---|
| public abstract Appendable normalize(CharSequence src, Appendable dest) Writes the normalized form of the source string to the destination Appendable and returns the destination Appendable. The source and destination strings must be different objects. Any
| |
| normalizeSecondAndAppend | back to summary |
|---|---|
| public abstract StringBuilder normalizeSecondAndAppend(StringBuilder first, CharSequence second) Appends the normalized form of the second string to the first string (merging them at the boundary) and returns the first string. The result is normalized if the first string was normalized. The first and second strings must be different objects.
| |
| spanQuickCheckYes | back to summary |
|---|---|
| public abstract int spanQuickCheckYes(CharSequence s) Returns the end of the normalized substring of the input string.
In other words, with The returned end index is usually one or more characters before the "no" or "maybe" character: The end index is at a normalization boundary. (See the class documentation for more about normalization boundaries.) When the goal is a normalized string and most input strings are expected to be normalized already, then call this method, and if it returns a prefix shorter than the input string, copy that prefix and use normalizeSecondAndAppend() for the remainder.
| |