Mercurial > hgrepos > Python2 > PyMuPDF
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2016 Nu-book Inc. | |
| 3 */ | |
| 4 // SPDX-License-Identifier: Apache-2.0 | |
| 5 | |
| 6 #include "TextEncoder.h" | |
| 7 | |
| 8 #include "CharacterSet.h" | |
| 9 #include "ECI.h" | |
| 10 #include "Utf.h" | |
| 11 #include "ZXAlgorithms.h" | |
| 12 #include "libzueci/zueci.h" | |
| 13 | |
| 14 #include <stdexcept> | |
| 15 | |
| 16 namespace ZXing { | |
| 17 | |
| 18 void TextEncoder::GetBytes(const std::string& str, CharacterSet charset, std::string& bytes) | |
| 19 { | |
| 20 int eci = ToInt(ToECI(charset)); | |
| 21 const int str_len = narrow_cast<int>(str.length()); | |
| 22 int eci_len; | |
| 23 | |
| 24 if (eci == -1) | |
| 25 eci = 899; // Binary | |
| 26 | |
| 27 bytes.clear(); | |
| 28 | |
| 29 int error_number = zueci_dest_len_eci(eci, reinterpret_cast<const unsigned char *>(str.data()), str_len, &eci_len); | |
| 30 if (error_number >= ZUECI_ERROR) // Shouldn't happen | |
| 31 throw std::logic_error("Internal error `zueci_dest_len_eci()`"); | |
| 32 | |
| 33 bytes.resize(eci_len); // Sufficient but approximate length | |
| 34 | |
| 35 error_number = zueci_utf8_to_eci(eci, reinterpret_cast<const unsigned char *>(str.data()), str_len, | |
| 36 reinterpret_cast<unsigned char *>(bytes.data()), &eci_len); | |
| 37 if (error_number >= ZUECI_ERROR) { | |
| 38 bytes.clear(); | |
| 39 throw std::invalid_argument("Unexpected charcode"); | |
| 40 } | |
| 41 | |
| 42 bytes.resize(eci_len); // Actual length | |
| 43 } | |
| 44 | |
| 45 void TextEncoder::GetBytes(const std::wstring& str, CharacterSet charset, std::string& bytes) | |
| 46 { | |
| 47 GetBytes(ToUtf8(str), charset, bytes); | |
| 48 } | |
| 49 | |
| 50 } // ZXing |
