Remove the old UTF-8 conversion routines

This commit is contained in:
Frédéric Mangano 2023-03-03 12:46:26 +09:00
parent 1d13c258e4
commit 54136057d8
3 changed files with 3 additions and 19 deletions

View File

@ -162,11 +162,9 @@ byte_string slurp_binary_file(const char* filename);
/** Convert a string from the system locales encoding to UTF-8. */
std::u8string encode_utf8(std::string_view);
std::string to_utf8(std::string_view); ///< \deprecated
/** Convert a string from UTF-8 to the system locales encoding. */
std::string decode_utf8(std::u8string_view);
std::string from_utf8(std::string_view); ///< \deprecated
/** Escape a string so that a POSIX shell interprets it as a single argument. */
std::string shell_escape(std::string_view word);

View File

@ -210,29 +210,18 @@ std::basic_string<OutChar> encoding_converter::convert(std::basic_string_view<In
return out;
}
static encoding_converter to_utf8_cvt("", "UTF-8");
static encoding_converter from_utf8_cvt("UTF-8", "");
std::u8string ot::encode_utf8(std::string_view in)
{
static encoding_converter to_utf8_cvt("", "UTF-8");
return to_utf8_cvt.convert<char, char8_t>(in);
}
std::string ot::to_utf8(std::string_view in)
{
return to_utf8_cvt.convert<char, char>(in);
}
std::string ot::decode_utf8(std::u8string_view in)
{
static encoding_converter from_utf8_cvt("UTF-8", "");
return from_utf8_cvt.convert<char8_t, char>(in);
}
std::string ot::from_utf8(std::string_view in)
{
return from_utf8_cvt.convert<char, char>(in);
}
std::string ot::shell_escape(std::string_view word)
{
std::string escaped_word;

View File

@ -48,15 +48,12 @@ void check_slurp()
void check_converter()
{
is(ot::from_utf8(ot::to_utf8("Éphémère")), "Éphémère", "from_utf8 reverts to_utf8");
is(ot::to_utf8(ot::from_utf8("Éphémère")), "Éphémère", "to_utf8 reverts from_utf8");
is(ot::decode_utf8(ot::encode_utf8("Éphémère")), "Éphémère", "decode_utf8 reverts encode_utf8");
opaque_is(ot::encode_utf8(ot::decode_utf8(u8"Éphémère")), u8"Éphémère",
"encode_utf8 reverts decode_utf8");
try {
ot::from_utf8("\xFF\xFF");
ot::decode_utf8((char8_t*) "\xFF\xFF");
throw failure("conversion from bad UTF-8 did not fail");
} catch (const ot::status&) {}
}