icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Provide a C++ interface to the collator

Open hsivonen opened this issue 1 year ago • 0 comments

Currently, the collator isn't exposed to C++ via Diplomat. It should be.

Apart from the constructor, the Collator object has three public methods in Rust:

  • compare() (takes guaranteed-valid UTF-8)
  • compare_utf8() (takes potentially-invalid UTF-8)
  • compare_utf16() (takes potentially-invalid UTF-16)

I expect these to be exposed to C++ as follows:

  • C++ compare() taking std::u16string_view: Rust compare_utf16()
  • C++ compare() taking std::string_view: Rust compare_utf8()
  • C++ compare_unsafe() taking std::string_view: Rust compare() with documentation note that the call is UB unless the C++ caller has ensured UTF-8 validity.

(Once we support C++20, there should be std::u8string_view overloads for the same things that have std::string_view versions.)

In Rust, these return Ordering. It's a bit unclear if they should return int with values -1, 0, 1 or something fancier in C++.

hsivonen avatar Jul 20 '22 07:07 hsivonen