From 8f389f14c0584861c712c049bdba3ed0d9036506 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 13 Jan 2019 09:41:13 -0500 Subject: QUtil::analyze_encoding --- libtests/qtest/qutil/qutil.out | 1 + libtests/qutil.cc | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'libtests') diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out index 50ec26f9..c0789a36 100644 --- a/libtests/qtest/qutil/qutil.out +++ b/libtests/qtest/qutil/qutil.out @@ -57,6 +57,7 @@ HAGOOGAMAGOOGLE: 0 bidirectional pdf doc done bidirectional win ansi done bidirectional mac roman done +analysis done ---- whoami quack1 quack2 diff --git a/libtests/qutil.cc b/libtests/qutil.cc index 355bb9a2..91a656be 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -262,6 +262,20 @@ void transcoding_test(std::string (*to_utf8)(std::string const&), } } +void check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16) +{ + bool has_8bit_chars = false; + bool is_valid_utf8 = false; + bool is_utf16 = false; + QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16); + if (! ((has_8bit_chars == has8bit) && + (is_valid_utf8 == utf8) && + (is_utf16 == utf16))) + { + std::cout << "analysis failed: " << str << std::endl; + } +} + void transcoding_test() { transcoding_test(&QUtil::pdf_doc_to_utf8, @@ -273,6 +287,11 @@ void transcoding_test() transcoding_test(&QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 255, "?"); std::cout << "bidirectional mac roman done" << std::endl; + check_analyze("pi = \317\200", true, true, false); + check_analyze("pi != \317", true, false, false); + check_analyze("pi != 22/7", false, false, false); + check_analyze(std::string("\xfe\xff\00\x51", 4), true, false, true); + std::cout << "analysis done" << std::endl; } void print_whoami(char const* str) -- cgit v1.2.3-54-g00ecf