Search documentation of Localize

# Localize.Collation.Nif (Localize v0.39.0)

Copy Markdown View Source

Collation NIF interface providing high-performance Unicode collation via ICU4C.

This module wraps the `nif_collation_cmp/10` function from `Localize.Nif` and provides encoding of collation options to ICU enum values.

## Summary

### Functions

available?()

Returns whether the collation NIF backend is available.

nif_compare(string_a, string_b, options)

Compare two strings using the ICU NIF collator with full option support.

reorder_codes_supported?(reorder_codes)

Returns whether all reorder codes in the list can be mapped to ICU values.

## Functions

# available?()

    @spec available?() :: boolean()

Returns whether the collation NIF backend is available.

### Returns

- `true` if the NIF shared library was loaded and the collation function is available.

- `false` otherwise.

# nif_compare(string_a, string_b, options)

    @spec nif_compare(String.t(), String.t(), Localize.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 `%Localize.Collation.Options{}` struct.

### Returns

- `:lt` if `string_a` sorts before `string_b`.

- `:eq` if `string_a` and `string_b` are collation-equal.

- `:gt` if `string_a` sorts after `string_b`.

# reorder_codes_supported?(reorder_codes)

    @spec reorder_codes_supported?([atom()]) :: boolean()

Returns whether all reorder codes in the list can be mapped to ICU values.

### Arguments

- `reorder_codes` - a list of script code atoms.

### Returns

- `true` if all codes are recognized.

- `false` if any code is unrecognized.

### Examples

    iex> Localize.Collation.Nif.reorder_codes_supported?([:Grek, :Latn])
    true

    iex> Localize.Collation.Nif.reorder_codes_supported?([:Unknown])
    false

    iex> Localize.Collation.Nif.reorder_codes_supported?([])
    true