Search documentation of Localize

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

Copy Markdown View Source

Constructs binary sort keys from processed collation elements.

Sort keys are multi-level byte sequences that can be compared with binary comparison (`<`, `>`, `==`) to determine string ordering.

Structure: [L1 weights] 0000 [L2 weights] 0000 [L3 weights] [0000 L4 weights]

## Summary

### Functions

build(processed_elements, options, original_string \\ nil)

Build a binary sort key from processed collation elements.

## Functions

# build(processed_elements, options, original_string \\ nil)

    @spec build(
      [{Localize.Collation.Element.t(), non_neg_integer()}],
      Localize.Collation.Options.t(),
      String.t() | nil
    ) :: binary()

Build a binary sort key from processed collation elements.

### Arguments

- `processed_elements` - a list of `{element, quaternary}` tuples as returned by `Localize.Collation.Variable.process/3`.

- `options` - a `%Localize.Collation.Options{}` struct controlling which levels to include.

- `original_string` - the original input string, used for the identical level (default: `nil`).

### Returns

A binary sort key where levels are separated by `<<0x00, 0x00>>`.

### Examples

    iex> elements = [{{0x23EC, 0x0020, 0x0008, false}, 0}]
    iex> options = Localize.Collation.Options.new(strength: :primary)
    iex> Localize.Collation.SortKey.build(elements, options)
    <<0x23, 0xEC>>