Optional NIF-based Unicode transforms using ICU4C.
This module provides high-performance Unicode transliteration by wrapping
ICU4C's utrans API via a Native Interface Function (NIF). When available,
transforms are dispatched to ICU for execution; otherwise, the pure-Elixir
engine is used automatically.
The NIF is opt-in and requires:
ICU system libraries installed (
libicuoricucoreon macOS).The
elixir_makedependency.Enable the NIF via either:
- Environment variable:
UNICODE_TRANSFORM_NIF=true mix compile - Application config in
config.exs:config :unicode_transform, :nif, true
- Environment variable:
The config key must be set in config.exs (not runtime.exs) because
it is evaluated at compile time to include the :elixir_make compiler.
If the NIF is not available, available?/0 returns false and the
pure-Elixir implementation is used automatically.
Summary
Functions
Returns whether the NIF transform backend is available.
Returns a list of all ICU-registered transliterator IDs.
Transforms a string using an ICU transliterator.
Functions
@spec available?() :: boolean()
Returns whether the NIF transform backend is available.
The NIF is considered available when it is enabled via the
UNICODE_TRANSFORM_NIF environment variable or the
:nif application config key, and the shared library
was loaded successfully.
Returns
trueif the NIF is enabled and the shared library was loaded.falseotherwise.
Examples
iex> is_boolean(Unicode.Transform.Nif.available?())
true
@spec available_ids() :: [String.t()]
Returns a list of all ICU-registered transliterator IDs.
Returns
A list of transform ID strings (e.g., ["ASCII-Latin", "Any-Accents", ...]).
Transforms a string using an ICU transliterator.
Arguments
id— the ICU transform ID (e.g.,"Latin-ASCII","Greek-Latin").text— the input string to transform.direction—0for forward (UTRANS_FORWARD),1for reverse (UTRANS_REVERSE).
Returns
{:ok, result}on success.{:error, reason}on failure.