Optional NIF-based collation using ICU's C library.
This module provides high-performance Unicode collation by wrapping ICU4C via a Native Interface Function (NIF). It supports all ICU-configurable collation attributes: strength, backwards (French), alternate handling, case first, case level, normalization, numeric collation, and script reordering.
The NIF is opt-in and requires:
- ICU system libraries installed (
libicuoricucoreon macOS) - The
elixir_makedependency - Enable the NIF via either:
- Environment variable:
CLDR_COLLATION_NIF=true mix compile - Application config in
config.exs:config :ex_cldr_collation, :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 collation backend is available.
Compare two strings using the ICU NIF collator with full option support.
Returns whether all reorder codes in the list can be mapped to ICU values.
Functions
@spec available?() :: boolean()
Returns whether the NIF collation backend is available.
Returns
trueif the NIF shared library was loaded successfully.falseif the NIF is not compiled or ICU libraries are missing.
Examples
iex> is_boolean(Cldr.Collation.Nif.available?())
true
@spec nif_compare(String.t(), String.t(), Cldr.Collation.Options.t()) :: :lt | :eq | :gt
Compare two strings using the ICU NIF collator with full option support.
Arguments
string_a- the first string to compare.string_b- the second string to compare.options- a%Cldr.Collation.Options{}struct.
Returns
:ltifstring_asorts beforestring_b.:eqifstring_aandstring_bare collation-equal.:gtifstring_asorts afterstring_b.
Returns whether all reorder codes in the list can be mapped to ICU values.
Arguments
reorder_codes- a list of script code atoms (e.g.,[:Grek, :Latn]).
Returns
trueif all codes are recognized.falseif any code is unrecognized.
Examples
iex> Cldr.Collation.Nif.reorder_codes_supported?([:Grek, :Latn])
true
iex> Cldr.Collation.Nif.reorder_codes_supported?([:Unknown])
false
iex> Cldr.Collation.Nif.reorder_codes_supported?([])
true