elixir-cldr / cldr_collation

CLDR Collation
Other
4 stars 4 forks source link

Support creating Rust collator resource references usable from Elixir #13

Open foxbenjaminfox opened 1 year ago

foxbenjaminfox commented 1 year ago

As described in #9, we want to also have an interface in which the user of the Elixir obtains a reference to a Collator Rust resource and uses it in multiple calls. This PR implements the NIF API for that interface.

This NIF API has a create_collator/2 function that takes a locale and an options map and returns a reference that can be passed as the first argument to sort_using_collator/2. For example:

collator = Cldr.Collation.Nif.create_collator("en", %{strength: :primary, alternate_handling: nil, case_first: nil, max_variable: nil, case_level: nil, numeric: nil, backward_second_level: nil})

assert Cldr.Collation.Nif.sort_using_collator(collator, ["AAAA", "AAAa"]) == ["AAAA", "AAAa"]