aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_String.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-05 19:00:18 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-06 04:59:27 +0100
commit089ce5902ec155ff3dce7bed7c12006a587d3db0 (patch)
tree8fdda222bc40b051ab811f621e8ce5b7661c6df5 /libqpdf/QPDF_String.cc
parentae18bfd142f2f9a19505971d4d197cb37ee86eee (diff)
downloadqpdf-089ce5902ec155ff3dce7bed7c12006a587d3db0.tar.zst
Move utf8_to_utf16 into QUtil
Diffstat (limited to 'libqpdf/QPDF_String.cc')
-rw-r--r--libqpdf/QPDF_String.cc57
1 files changed, 1 insertions, 56 deletions
diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc
index 633f1699..7cfb6bcc 100644
--- a/libqpdf/QPDF_String.cc
+++ b/libqpdf/QPDF_String.cc
@@ -64,65 +64,10 @@ QPDF_String::~QPDF_String()
{
}
-enum encoding_e { e_utf16 };
-
-static
-std::string
-transcode_utf8(std::string const& utf8_val, encoding_e encoding)
-{
- std::string result = "\xfe\xff";
- size_t len = utf8_val.length();
- for (size_t i = 0; i < len; ++i)
- {
- unsigned char ch = static_cast<unsigned char>(utf8_val.at(i));
- if (ch < 128)
- {
- result += QUtil::toUTF16(ch);
- }
- else
- {
- size_t bytes_needed = 0;
- unsigned bit_check = 0x40;
- unsigned char to_clear = 0x80;
- while (ch & bit_check)
- {
- ++bytes_needed;
- to_clear |= bit_check;
- bit_check >>= 1;
- }
-
- if (((bytes_needed > 5) || (bytes_needed < 1)) ||
- ((i + bytes_needed) >= len))
- {
- result += "\xff\xfd";
- }
- else
- {
- unsigned long codepoint = (ch & ~to_clear);
- while (bytes_needed > 0)
- {
- --bytes_needed;
- ch = utf8_val.at(++i);
- if ((ch & 0xc0) != 0x80)
- {
- --i;
- codepoint = 0xfffd;
- break;
- }
- codepoint <<= 6;
- codepoint += (ch & 0x3f);
- }
- result += QUtil::toUTF16(codepoint);
- }
- }
- }
- return result;
-}
-
QPDF_String*
QPDF_String::new_utf16(std::string const& utf8_val)
{
- return new QPDF_String(transcode_utf8(utf8_val, e_utf16));
+ return new QPDF_String(QUtil::utf8_to_utf16(utf8_val));
}
std::string