View Source Cldr.Collation (Cldr Collation v0.7.5)
Implements the Unicode collation rules based on the CLDR root collation which in turn is based upon the Unicode DUCET table.
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.
Types
@type comparison() :: :lt | :eq | :gt
@type options() :: [{:casing, :sensitive | :insensitive}]
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
string_1is an aString.t/0string_2is an aString.t/0optionsis a keyword list of options
Options
:casingis either:sensitiveor:insensitiveindicating if collation is to be case sensitive or not. The default is:insensitive.
Returns
- Either of
:lt,:eqor:gtsignifying ifstring_1is less than, equal to or greater thanstring_2.
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
stringsis an enumerable of typet:String.t()optionsis a keyword list of options
Options
casingis either:sensitiveor:insensitiveindicating if collation is to be case sensitive or not. The default is:insensitive
Returns
- An ordered list of
t:String.t()
Examples
iex> Cldr.Collation.sort ["á", "b", "A"]
["á", "A", "b"]
iex> Cldr.Collation.sort ["á", "b", "A"], casing: :sensitive
["A", "á", "b"]