Cldr.Collation.SortKey (Cldr Collation v1.1.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 a binary sort key from processed collation elements.

Functions

build(processed_elements, options, original_string \\ nil)

Build a binary sort key from processed collation elements.

Constructs a multi-level binary key by extracting weights at each level (primary, secondary, tertiary, quaternary, identical) separated by 0x0000.

Arguments

  • processed_elements - a list of {element, quaternary} tuples as returned by Cldr.Collation.Variable.process/3.
  • options - a %Cldr.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>>. The number of levels included depends on the :strength option.

Examples

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