Unicode.Transform.Builtin (Unicode Transform v1.1.0)

Copy Markdown View Source

Implements built-in transforms defined by the Unicode Standard.

These transforms are not defined by rules but by operations in the Unicode Standard:

  • Any-NFC, Any-NFD, Any-NFKC, Any-NFKD — normalization forms.

  • Any-Lower, Any-Upper, Any-Title — case transformations.

  • Any-Null — identity (no effect).

  • Any-Remove — removes all characters.

Summary

Functions

Applies a built-in transform to a string.

Returns whether the given transform name is a built-in transform.

Returns true if the given name is a case transform (Upper, Lower, Title).

Returns the inverse of a built-in transform name.

Functions

apply(string, name)

@spec apply(String.t(), String.t()) :: String.t()

Applies a built-in transform to a string.

Arguments

  • string — the input string.

  • name — the transform name.

Returns

The transformed string.

Examples

iex> Unicode.Transform.Builtin.apply("hello", "Upper")
"HELLO"

# NFD decomposes "Ä" (U+00C4) into "A" plus a combining diaeresis.
iex> byte_size(Unicode.Transform.Builtin.apply("Ä", "NFD"))
3

builtin?(name)

@spec builtin?(String.t()) :: boolean()

Returns whether the given transform name is a built-in transform.

Arguments

  • name — the transform name string.

Returns

true if the transform is built-in, false otherwise.

case_transform?(name)

@spec case_transform?(String.t()) :: boolean()

Returns true if the given name is a case transform (Upper, Lower, Title).

Arguments

  • name — the transform name.

Returns

true if the transform is a case transform, false otherwise.

inverse(name)

@spec inverse(String.t()) :: String.t() | nil

Returns the inverse of a built-in transform name.

Arguments

  • name — the transform name.

Returns

The inverse transform name, or nil if no inverse exists.