View Source Cldr.Collation (Cldr Collation v0.7.2)

Implements the Unicode collation rules based on the CLDR root collation which in turn is based upon the Unicode DUCET table.

Link to this section Summary

Functions

Compares two strings according to the Unicode collation rules with the CLDR root collation which is based upon the Unicode DUCET table.

Sorts a list of strings according to the Unicode collation rules with the CLDR root collation which is based upon the Unicode DUCET table.

Link to this section Types

@type comparison() :: :lt | :eq | :gt
@type options() :: [{:casing, :sensitive | :insensitive}]

Link to this section Functions

Link to this function

compare(string_1, string_2, options \\ [casing: :insensitive])

View Source
@spec compare(string_1 :: String.t(), string_2 :: String.t(), options()) ::
  comparison()

Compares two strings according to the Unicode collation rules with the CLDR root collation which is based upon the Unicode DUCET table.

arguments

Arguments

options

Options

  • :casing is either :sensitive or :insensitive indicating if collation is to be case sensitive or not. The default is :insensitive.

returns

Returns

  • Either of :lt, :eq or :gt signifying if string_1 is less than, equal to or greater than string_2.

examples

Examples

iex> Cldr.Collation.compare "á", "A", casing: :sensitive
:gt

iex> Cldr.Collation.compare "á", "A", casing: :insensitive
:eq
Link to this function

sort(list, options \\ [casing: :insensitive])

View Source
@spec sort([String.t(), ...], options()) :: [String.t(), ...]

Sorts a list of strings according to the Unicode collation rules with the CLDR root collation which is based upon the Unicode DUCET table.

This collation does not aim to provide precisely correct ordering for each language and script; tailoring would be required for correct language handling in almost all cases.

The goal is instead to have all the other characters, those that are not tailored, show up in a reasonable order.

arguments

Arguments

  • strings is an enumerable of type t:String.t()

  • options is a keyword list of options

options

Options

  • casing is either :sensitive or :insensitive indicating if collation is to be case sensitive or not. The default is :insensitive

returns

Returns

  • An ordered list of t:String.t()

examples

Examples

iex> Cldr.Collation.sort ["á", "b", "A"]
["á", "A", "b"]

iex> Cldr.Collation.sort ["á", "b", "A"], casing: :sensitive
["A", "á", "b"]