Date: Thu, 4 May 2023 08:19:15 +0200
On 04/05/2023 04.06, Zach Laine via SG16 wrote:
> So, what do people suggest here as the adaptor mechanism? Something like:
>
> std::vector<int> code_points = /* something from ICU */;
>
> auto r = code_points | std::uc::trust_me_its_utf32 | std::uc::as_utf16;
>
> ? Something else?
As a first order of approximation,
auto r = code_points | std::views::transform([](int c) { return static_cast<char32_t>(c); }) | std::uc::to_utf16;
or, equivalently,
auto r = std::views::transform(code_points, [](int c) { return static_cast<char32_t>(c); }) | std::uc::to_utf16;
If there is a feeling we should provide
auto r = code_points | std::views::to_char<char32_t> | std::uc::to_utf16;
as a short-hand for the "transform" invocation (maybe with no-loss constraints),
then we could do that.
Jens
> So, what do people suggest here as the adaptor mechanism? Something like:
>
> std::vector<int> code_points = /* something from ICU */;
>
> auto r = code_points | std::uc::trust_me_its_utf32 | std::uc::as_utf16;
>
> ? Something else?
As a first order of approximation,
auto r = code_points | std::views::transform([](int c) { return static_cast<char32_t>(c); }) | std::uc::to_utf16;
or, equivalently,
auto r = std::views::transform(code_points, [](int c) { return static_cast<char32_t>(c); }) | std::uc::to_utf16;
If there is a feeling we should provide
auto r = code_points | std::views::to_char<char32_t> | std::uc::to_utf16;
as a short-hand for the "transform" invocation (maybe with no-loss constraints),
then we could do that.
Jens
Received on 2023-05-04 06:19:20