diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-06-21 19:05:48 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-06-21 21:57:13 +0200 |
commit | e44c395c51518bafbf8f8466ea5a0f4b1f2b2efe (patch) | |
tree | 95da31b1da0055ee2b605272f7079c7ea230584c /libqpdf | |
parent | 44674a3e58882ea95d6ee54fa3e16c553c0afb3e (diff) | |
download | qpdf-e44c395c51518bafbf8f8466ea5a0f4b1f2b2efe.tar.zst |
QUtil::toUTF16
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QUtil.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 39118854..e2bc0bac 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -506,6 +506,41 @@ QUtil::toUTF8(unsigned long uval) return result; } +std::string +QUtil::toUTF16(unsigned long uval) +{ + std::string result; + if ((uval >= 0xd800) && (uval <= 0xdfff)) + { + result = "\xff\xfd"; + } + else if (uval <= 0xffff) + { + char out[2]; + out[0] = (uval & 0xff00) >> 8; + out[1] = (uval & 0xff); + result = std::string(out, 2); + } + else if (uval <= 0x10ffff) + { + char out[4]; + uval -= 0x10000; + unsigned short high = ((uval & 0xffc00) >> 10) + 0xd800; + unsigned short low = (uval & 0x3ff) + 0xdc00; + out[0] = (high & 0xff00) >> 8; + out[1] = (high & 0xff); + out[2] = (low & 0xff00) >> 8; + out[3] = (low & 0xff); + result = std::string(out, 4); + } + else + { + result = "\xff\xfd"; + } + + return result; +} + // Random data support long |