cpp-common/bt2c: add `UnicodeConv` class
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 3 May 2024 16:54:10 +0000 (12:54 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
commitfb9a08c30c8bc0073dfe91be775aceee0951ac18
tree5f1e5e5fe4d1a6627e826e108f99fcf02c8074ab
parenta804026d23ba45312488cd6595cdcbfb5031584d
cpp-common/bt2c: add `UnicodeConv` class

Add the `UnicodeConv` class, which currently implements conversion
from (UTF-16, UTF-32) × (BE, LE) to UTF-8.

The `UnicodeConv` class uses `g_iconv` from GLib internally to make
the conversions.  It has a vector member that is used as an output
buffer.  Public conversion methods accept a span of
`const std::uint8_t`, and return a span `std::uint8_t` which is a view
on that internal vector.

Add a test which:

✤ Converts some hardcoded UTF-16 and UTF-32 strings to UTF-8 and
  verifies the result against a reference UTF-8 string.

✤ Feeds the UTF-16 and UTF-32 conversion methods with truncated strings
  and verifies that they throw and append specific causes to the error
  of the current thread.

Change-Id: I962bd49261a3d9779ed6a24a26c7800a24beb719
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12715
src/Makefile.am
src/cpp-common/bt2c/unicode-conv.cpp [new file with mode: 0644]
src/cpp-common/bt2c/unicode-conv.hpp [new file with mode: 0644]
tests/Makefile.am
tests/cpp-common/test-unicode-conv.cpp [new file with mode: 0644]
This page took 0.02429 seconds and 4 git commands to generate.