diff --git a/README.md b/README.md index 5fa63bcf..a9714aef 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ C++ 17 [deprecated the standard library's `` header file](https://www.o There are broadly three ways to use the icubaby library: -1. C++ 20 Range Adaptor +1. [C++ 20 Range Adaptor](#c-20-range-adaptor) 2. An iterator interface 3. Manually driving the conversion @@ -37,41 +37,7 @@ std::vector out; std::ranges::copy(r, std::back_inserter(out)); ~~~ -This code wants to convert a single Unicode code-point 😀 (U+1F600 GRINNING FACE) from UTF-32 to UTF-16. -As in the previous examples, the `out` vector will contain a two UTF-16 code units 0xD83D and 0xDE00. - -#### Disecting this code - -1. Define the input range: - - ~~~cpp - auto const in = std::array{char32_t{0x1F600}}; - ~~~ - - We express the input as a container with our input text consisting simply of U+1F600 GRINNING FACE expressed in UTF-32. - -2. Create a range with a view of our container and pass it to the icubaby `transcode` range adaptor: - - ~~~cpp - auto r = in | icubaby::ranges::transcode; - ~~~ - - The first template argument for icubaby::ranges::transcode<> is the encoding of the input text (one of `icubaby::char8`, `char16_t`, `char32_t`), the second argument is the desired encoding of the output text. - - We now have the range `r` containing the UTF-16 code-units that correspond to the original input text. - -3. The final step is to record the values within the range `r`. In C++ 20, this can be achieved with the [std::ranges::copy()](https://en.cppreference.com/w/cpp/algorithm/ranges/copy) algorithm: - - ~~~cpp - std::vector out; - std::ranges::copy(r, std::back_inserter(out)); - ~~~ - - If you are using the C++ 23 ranges library, you can simplify this even further using [std::ranges::to()](https://en.cppreference.com/w/cpp/ranges/to): - - ~~~cpp - auto const out = r | std::ranges::to (); - ~~~ +This code converts a single Unicode code-point 😀 (U+1F600 GRINNING FACE) from UTF-32 to UTF-16 and will copy two UTF-16 code-units (0xD83D and 0xDE00) into the `out` vector. See the [C++20 Range Adaptor documentation](https://paulhuggett.github.io/icubaby/cxx20-range-adaptor.html) for more details. ### The Iterator Interface