comparison mupdf-source/thirdparty/zxing-cpp/core/src/ByteArray.h @ 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 * Copyright 2022 Axel Waggershauser
4 */
5 // SPDX-License-Identifier: Apache-2.0
6
7 #pragma once
8
9 #include <cstdint>
10 #include <cstdio>
11 #include <string>
12 #include <string_view>
13 #include <vector>
14
15 namespace ZXing {
16
17 /**
18 ByteArray is an extension of std::vector<unsigned char>.
19 */
20 class ByteArray : public std::vector<uint8_t>
21 {
22 public:
23 ByteArray() = default;
24 ByteArray(std::initializer_list<uint8_t> list) : std::vector<uint8_t>(list) {}
25 explicit ByteArray(int len) : std::vector<uint8_t>(len, 0) {}
26 explicit ByteArray(const std::string& str) : std::vector<uint8_t>(str.begin(), str.end()) {}
27
28 void append(const ByteArray& other) { insert(end(), other.begin(), other.end()); }
29
30 std::string_view asString(size_t pos = 0, size_t len = std::string_view::npos) const
31 {
32 return std::string_view(reinterpret_cast<const char*>(data()), size()).substr(pos, len);
33 }
34 };
35
36 inline std::string ToHex(const ByteArray& bytes)
37 {
38 std::string res(bytes.size() * 3, ' ');
39
40 for (size_t i = 0; i < bytes.size(); ++i)
41 {
42 #ifdef _MSC_VER
43 sprintf_s(&res[i * 3], 4, "%02X ", bytes[i]);
44 #else
45 snprintf(&res[i * 3], 4, "%02X ", bytes[i]);
46 #endif
47 }
48
49 return res.substr(0, res.size()-1);
50 }
51
52 } // ZXing