UnicodeNormalization Class
Provides the Unicode normalization forms.
public static class UnicodeNormalizationRemarks
The forms are those of Unicode Standard Annex #15 for UnicodeProperties.UnicodeVersion. They do not use the globalization library of the platform: the results are the same on every platform and every framework version, including in globalization-invariant mode, where String.Normalize only handles ASCII.
An unpaired surrogate is not a character: it is copied as is and never combines. The methods never throw for the content of the text.
See also
Properties
| Name | Description |
|---|---|
| MaxCanonicalDecompositionLength | Gets the greatest number of code points of the full canonical decomposition of one code point. |
MaxCanonicalDecompositionLength
UnicodeNormalization.csMethods
| Name | Description |
|---|---|
| GetCanonicalDecomposition(int, Span<int>) | Gets the full canonical decomposition of a code point. |
| GetNormalizedLength(ReadOnlySpan<char>, NormalizationForm) | Gets the length of a text once normalized. |
| IsNormalized(ReadOnlySpan<char>, NormalizationForm) | Determines whether a text is in a normalization form. |
| Normalize(string, NormalizationForm) | Returns a text in a normalization form. |
| TryComposeCanonical(int, int, int) | Gets the primary composite of two code points. |
| TryDecomposeCanonical(int, int, int) | Gets the canonical decomposition mapping of a code point: one step of decomposition. |
| TryNormalize(ReadOnlySpan<char>, Span<char>, int, NormalizationForm) | Writes a text in a normalization form to a buffer. |
GetCanonicalDecomposition(int, Span<int>)
UnicodeNormalization.csGets the full canonical decomposition of a code point.
Parameters
codePointint- The code point.
destinationSpan<int>- The buffer that receives the code points.
UnicodeNormalization.MaxCanonicalDecompositionLengthelements are always enough.
Returns
int The number of code points written; 1, the code point itself, when it has no decomposition.
Exceptions
ArgumentExceptiondestinationis too small.
GetNormalizedLength(ReadOnlySpan<char>, NormalizationForm)
UnicodeNormalization.csGets the length of a text once normalized.
public static int GetNormalizedLength(ReadOnlySpan<char> source, NormalizationForm form = (NormalizationForm)1)Parameters
sourceReadOnlySpan<char>- The text.
formNormalizationForm- The normalization form.
Returns
int The number of UTF-16 code units UnicodeNormalization.TryNormalize writes.
Exceptions
ArgumentOutOfRangeExceptionformis not a defined value.
IsNormalized(ReadOnlySpan<char>, NormalizationForm)
UnicodeNormalization.csDetermines whether a text is in a normalization form.
public static bool IsNormalized(ReadOnlySpan<char> value, NormalizationForm form = (NormalizationForm)1)Parameters
valueReadOnlySpan<char>- The text.
formNormalizationForm- The normalization form.
Returns
bool true when normalizing the text would not change it.
Exceptions
ArgumentOutOfRangeExceptionformis not a defined value.
Normalize(string, NormalizationForm)
UnicodeNormalization.csReturns a text in a normalization form.
public static string Normalize(string value, NormalizationForm form = (NormalizationForm)1)Parameters
valuestring- The text.
formNormalizationForm- The normalization form.
Returns
string The normalized text; value itself when it is already normalized.
Exceptions
ArgumentNullExceptionvalueisnull.ArgumentOutOfRangeExceptionformis not a defined value.
TryComposeCanonical(int, int, int)
UnicodeNormalization.csGets the primary composite of two code points.
TryDecomposeCanonical(int, int, int)
UnicodeNormalization.csGets the canonical decomposition mapping of a code point: one step of decomposition.
Parameters
codePointint- The code point.
firstint- The first code point of the mapping, when the method returns
true; otherwisecodePoint. secondint- The second code point of the mapping, or -1 when the mapping is a single code point.
Returns
bool true when the code point has a canonical decomposition.
Remarks
The first code point can have a decomposition of its own; the second one never has. A Hangul syllable is decomposed into its leading syllable and its trailing consonant, or into its two jamos when it has no trailing consonant.
TryNormalize(ReadOnlySpan<char>, Span<char>, int, NormalizationForm)
UnicodeNormalization.csWrites a text in a normalization form to a buffer.
public static bool TryNormalize(ReadOnlySpan<char> source, Span<char> destination, out int charsWritten, NormalizationForm form = (NormalizationForm)1)Parameters
sourceReadOnlySpan<char>- The text.
destinationSpan<char>- The buffer that receives the normalized text. It must not overlap
source. charsWrittenint- The number of UTF-16 code units written, when the method returns
true; otherwise 0. formNormalizationForm- The normalization form.
Returns
bool false when destination is too small; nothing meaningful is written in that case.
Exceptions
ArgumentOutOfRangeExceptionformis not a defined value.