Search documentation of Localize

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

Copy Markdown View Source

A Collation Element (CE) with primary, secondary, and tertiary weights.

Elements are represented as `{primary, secondary, tertiary, variable}` tuples for compact persistent_term storage. Constructor and accessor functions provide a readable interface.

Weights follow the CLDR/UCA specification:

- Primary: base character identity (0x0000-0xFFFF).

- Secondary: accent/diacritic differences (0x0000-0x01FF).

- Tertiary: case/width/variant differences (0x0000-0x003F).

## Summary

### Types

t()

### Functions

ignorable?(arg1)

Check if a collation element is completely ignorable.

new(primary \\ 0, secondary \\ 0, tertiary \\ 0, variable \\ false)

Create a new collation element tuple.

primary(arg)

Get the primary weight of a collation element.

primary_ignorable?(arg1)

Check if a collation element is primary-ignorable.

secondary(arg)

Get the secondary weight of a collation element.

tertiary(arg)

Get the tertiary weight of a collation element.

variable?(arg1, arg2)

Check if a collation element is a variable element.

## Types

# t()

    @type t() :: {non_neg_integer(), non_neg_integer(), non_neg_integer(), boolean()}

## Functions

# ignorable?(arg1)

    @spec ignorable?(t()) :: boolean()

Check if a collation element is completely ignorable.

A completely ignorable element has all weights (primary, secondary, tertiary) set to zero.

### Arguments

- `element` - a collation element tuple.

### Returns

- `true` if all weights are zero.

- `false` otherwise.

### Examples

    iex> Localize.Collation.Element.ignorable?({0, 0, 0, false})
    true

    iex> Localize.Collation.Element.ignorable?({0, 0x0020, 0, false})
    false

# new(primary \\ 0, secondary \\ 0, tertiary \\ 0, variable \\ false)

    @spec new(non_neg_integer(), non_neg_integer(), non_neg_integer(), boolean()) :: t()

Create a new collation element tuple.

### Arguments

- `primary` - the primary weight (default: `0`).

- `secondary` - the secondary weight (default: `0`).

- `tertiary` - the tertiary weight (default: `0`).

- `variable` - whether this is a variable element (default: `false`).

### Returns

A `{primary, secondary, tertiary, variable}` tuple.

### Examples

    iex> Localize.Collation.Element.new(0x23EC, 0x0020, 0x0008, false)
    {0x23EC, 0x0020, 0x0008, false}

# primary(arg)

    @spec primary(t()) :: non_neg_integer()

Get the primary weight of a collation element.

### Arguments

- `element` - a collation element tuple.

### Returns

The primary weight as a non-negative integer.

### Examples

    iex> Localize.Collation.Element.primary({0x23EC, 0x0020, 0x0008, false})
    0x23EC

# primary_ignorable?(arg1)

    @spec primary_ignorable?(t()) :: boolean()

Check if a collation element is primary-ignorable.

A primary-ignorable element has a primary weight of zero but may have non-zero secondary or tertiary weights (e.g., combining accents).

### Arguments

- `element` - a collation element tuple.

### Returns

- `true` if the primary weight is zero.

- `false` otherwise.

### Examples

    iex> Localize.Collation.Element.primary_ignorable?({0, 0x0024, 0x0002, false})
    true

    iex> Localize.Collation.Element.primary_ignorable?({0x23EC, 0x0020, 0x0002, false})
    false

# secondary(arg)

    @spec secondary(t()) :: non_neg_integer()

Get the secondary weight of a collation element.

### Arguments

- `element` - a collation element tuple.

### Returns

The secondary weight as a non-negative integer.

### Examples

    iex> Localize.Collation.Element.secondary({0x23EC, 0x0020, 0x0008, false})
    0x0020

# tertiary(arg)

    @spec tertiary(t()) :: non_neg_integer()

Get the tertiary weight of a collation element.

### Arguments

- `element` - a collation element tuple.

### Returns

The tertiary weight as a non-negative integer.

### Examples

    iex> Localize.Collation.Element.tertiary({0x23EC, 0x0020, 0x0008, false})
    0x0008

# variable?(arg1, arg2)

    @spec variable?(t(), non_neg_integer()) :: boolean()

Check if a collation element is a variable element.

Variable elements represent spaces, punctuation, symbols, and currency signs. They are identified by the `variable: true` flag set during parsing of the collation table (derived from the `[first variable]` and `[last variable]` boundaries in FractionalUCA.txt).

### Arguments

- `element` - a collation element tuple.

- `max_variable_primary` - the maximum primary weight for variable elements (unused, retained for API compatibility).

### Returns

- `true` if the element is marked as variable and has a non-zero primary weight.

- `false` otherwise.

### Examples

    iex> Localize.Collation.Element.variable?({0x0269, 0x0020, 0x0002, true}, 0x0B61)
    true

    iex> Localize.Collation.Element.variable?({0x23EC, 0x0020, 0x0002, false}, 0x0B61)
    false