cpp-common/bt2c: add `bt2c::CStringView`
A `bt2c::CStringView` is like a `bt2s::string_view`, but specialized for
strings that are known to be null-terminated (C strings).
This is useful when wrapping an existing API which has functions
returning `const char *`: return `bt2c::CStringView` from the wrappers
at no cost, but with improved usability:
if (myObj.name().len() >= 16) {
// ...
}
vs.
if (std::strlen(myObj.name()) >= 16) {
// ...
}
A `bt2c::CStringView` only computes the length of the underlying
C string with std::strlen() when needed. It can convert to `std::string`
and `bt2s::string_view`.
`c-string-view.hpp` includes an {fmt} formatter for convenience. It
writes `(null)` when the underlying pointer is null, just like the glibc
printf() does.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I522ce586e9966736dadeeabf30f02da5dc62c80c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11485
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.024674 seconds and 4 git commands to generate.