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
@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
string_1
is an aString.t/0
string_2
is an aString.t/0
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
- Either of
:lt
,:eq
or:gt
signifying ifstring_1
is less than, equal to or greater thanstring_2
.
examples
Examples
iex> Cldr.Collation.compare "á", "A", casing: :sensitive
:gt
iex> Cldr.Collation.compare "á", "A", casing: :insensitive
:eq
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 typet: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"]