Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/thirdparty/zxing-cpp/core/src/TextEncoder.cpp @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mupdf-source/thirdparty/zxing-cpp/core/src/TextEncoder.cpp Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,50 @@ +/* +* Copyright 2016 Nu-book Inc. +*/ +// SPDX-License-Identifier: Apache-2.0 + +#include "TextEncoder.h" + +#include "CharacterSet.h" +#include "ECI.h" +#include "Utf.h" +#include "ZXAlgorithms.h" +#include "libzueci/zueci.h" + +#include <stdexcept> + +namespace ZXing { + +void TextEncoder::GetBytes(const std::string& str, CharacterSet charset, std::string& bytes) +{ + int eci = ToInt(ToECI(charset)); + const int str_len = narrow_cast<int>(str.length()); + int eci_len; + + if (eci == -1) + eci = 899; // Binary + + bytes.clear(); + + int error_number = zueci_dest_len_eci(eci, reinterpret_cast<const unsigned char *>(str.data()), str_len, &eci_len); + if (error_number >= ZUECI_ERROR) // Shouldn't happen + throw std::logic_error("Internal error `zueci_dest_len_eci()`"); + + bytes.resize(eci_len); // Sufficient but approximate length + + error_number = zueci_utf8_to_eci(eci, reinterpret_cast<const unsigned char *>(str.data()), str_len, + reinterpret_cast<unsigned char *>(bytes.data()), &eci_len); + if (error_number >= ZUECI_ERROR) { + bytes.clear(); + throw std::invalid_argument("Unexpected charcode"); + } + + bytes.resize(eci_len); // Actual length +} + +void TextEncoder::GetBytes(const std::wstring& str, CharacterSet charset, std::string& bytes) +{ + GetBytes(ToUtf8(str), charset, bytes); +} + +} // ZXing
