diff options
author | Jack Lloyd <[email protected]> | 2017-11-09 12:19:28 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-11-09 12:19:28 -0500 |
commit | 2aea9e3b2d6d9a3ad1f5e3c76e7e0d99c0872122 (patch) | |
tree | cf9d6e0763def177e4452119e6603dfc2ff49b9b /src/tests/test_utils.cpp | |
parent | 7e3cfd7eb4cc9165c9c53c81c3613c23db433cd7 (diff) |
Add UCS-2 and UCS-4 to UTF-8 conversion functions
Crosschecked by fuzzing and comparing with iconv
Needed in #1250
Diffstat (limited to 'src/tests/test_utils.cpp')
-rw-r--r-- | src/tests/test_utils.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index 57cd3208c..da2d25d5e 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -409,22 +409,33 @@ class Charset_Tests final : public Text_Based_Test const std::vector<uint8_t> in = get_req_bin(vars, "In"); const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::string in_str(in.begin(), in.end()); + std::string converted; - if(type == "UTF16-LATIN1") + + if(type == "UCS2-UTF8") + { + converted = Botan::ucs2_to_utf8(in.data(), in.size()); + } + else if(type == "UCS4-UTF8") + { + converted = Botan::ucs4_to_utf8(in.data(), in.size()); + } + else if(type == "UTF16-LATIN1") { - converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + converted = Botan::Charset::transcode(in_str, Botan::Character_Set::LATIN1_CHARSET, Botan::Character_Set::UCS2_CHARSET); } else if(type == "UTF8-LATIN1") { - converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + converted = Botan::Charset::transcode(in_str, Botan::Character_Set::LATIN1_CHARSET, Botan::Character_Set::UTF8_CHARSET); } else if(type == "LATIN1-UTF8") { - converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + converted = Botan::Charset::transcode(in_str, Botan::Character_Set::UTF8_CHARSET, Botan::Character_Set::LATIN1_CHARSET); } |