Repository navigation
TStringConverter
#include <certpp/string.hpp> --- certpp
Template: template <typename TDest, typename TSrc>
A template class for converting strings between different character types. @tparam TDest The destination character type. @tparam TSrc The source character type.
Measures the length of the source string span.
-
src--- The source string span.
Returns: The length of the source string span.
Converts a source string span to a destination string span.
-
dst--- The destination string span. -
src--- The source string span.
Returns: The number of characters converted.
Transcodes between char and wchar_t one span at a time -- what TString::convertTo() uses underneath. The template arguments are <destination, source> in that order, and measure() has to run before convert() because the destination length is not the source length.
// given: const CString& narrow
TStringConverter<wchar_t, char> conv;
TReadOnlySpan<char> src = narrow.toSpan();
const size_t units = conv.measure(src);
if (units == 0) {
return;
}
CWideString wide;
if (!wide.resize(units)) {
return;
}
// An instance carries an mbstate_t, so one converter belongs to one conversion: reuse it
// for a second, unrelated string and it resumes mid-sequence.
TSpan<wchar_t> dst = wide.toSpan();
const size_t converted = conv.convert(dst, src);
if (converted != units) {
wide.clear();
}Reference generated from certpp/string.hpp at commit 0834b29 (v1.0.1). The header is authoritative --- if this page disagrees with it, the header is right and this page needs regenerating.