Import Cobalt 16.154703
diff --git a/src/third_party/QR-Code-generator/cpp/BitBuffer.cpp b/src/third_party/QR-Code-generator/cpp/BitBuffer.cpp
new file mode 100644
index 0000000..d6e8cb2
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/BitBuffer.cpp
@@ -0,0 +1,48 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#include "BitBuffer.hpp"
+
+
+namespace qrcodegen {
+
+BitBuffer::BitBuffer()
+ : std::vector<bool>() {}
+
+
+std::vector<std::uint8_t> BitBuffer::getBytes() const {
+ std::vector<std::uint8_t> result(size() / 8 + (size() % 8 == 0 ? 0 : 1));
+ for (std::size_t i = 0; i < size(); i++)
+ result[i >> 3] |= (*this)[i] ? 1 << (7 - (i & 7)) : 0;
+ return result;
+}
+
+
+void BitBuffer::appendBits(std::uint32_t val, int len) {
+ if (len < 0 || len > 31 || val >> len != 0)
+ throw "Value out of range";
+ for (int i = len - 1; i >= 0; i--) // Append bit by bit
+ this->push_back(((val >> i) & 1) != 0);
+}
+
+}
diff --git a/src/third_party/QR-Code-generator/cpp/BitBuffer.hpp b/src/third_party/QR-Code-generator/cpp/BitBuffer.hpp
new file mode 100644
index 0000000..be00ee4
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/BitBuffer.hpp
@@ -0,0 +1,57 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <vector>
+
+
+namespace qrcodegen {
+
+/*
+ * An appendable sequence of bits (0's and 1's).
+ */
+class BitBuffer final : public std::vector<bool> {
+
+ /*---- Constructor ----*/
+
+ // Creates an empty bit buffer (length 0).
+ public: BitBuffer();
+
+
+
+ /*---- Methods ----*/
+
+ // Packs this buffer's bits into bytes in big endian,
+ // padding with '0' bit values, and returns the new vector.
+ public: std::vector<std::uint8_t> getBytes() const;
+
+
+ // Appends the given number of low bits of the given value
+ // to this sequence. Requires 0 <= val < 2^len.
+ public: void appendBits(std::uint32_t val, int len);
+
+};
+
+}
diff --git a/src/third_party/QR-Code-generator/cpp/Makefile b/src/third_party/QR-Code-generator/cpp/Makefile
new file mode 100644
index 0000000..151a4da
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/Makefile
@@ -0,0 +1,66 @@
+#
+# Makefile for QR Code generator (C++)
+#
+# Copyright (c) Project Nayuki. (MIT License)
+# https://www.nayuki.io/page/qr-code-generator-library
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+# the Software, and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+# - The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# - The Software is provided "as is", without warranty of any kind, express or
+# implied, including but not limited to the warranties of merchantability,
+# fitness for a particular purpose and noninfringement. In no event shall the
+# authors or copyright holders be liable for any claim, damages or other
+# liability, whether in an action of contract, tort or otherwise, arising from,
+# out of or in connection with the Software or the use or other dealings in the
+# Software.
+#
+
+
+# ---- Configuration options ----
+
+# External/implicit variables:
+# - CXX: The C++ compiler, such as g++ or clang++.
+# - CXXFLAGS: Any extra user-specified compiler flags (can be blank).
+
+# Mandatory compiler flags
+CXXFLAGS += -std=c++11
+# Diagnostics. Adding '-fsanitize=address' is helpful for most versions of Clang and newer versions of GCC.
+CXXFLAGS += -Wall -fsanitize=undefined
+# Optimization level
+CXXFLAGS += -O1
+
+
+# ---- Controlling make ----
+
+# Clear default suffix rules
+.SUFFIXES:
+
+# Don't delete object files
+.SECONDARY:
+
+# Stuff concerning goals
+.DEFAULT_GOAL = all
+.PHONY: all clean
+
+
+# ---- Targets to build ----
+
+LIBSRC = BitBuffer QrCode QrSegment
+MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker
+
+# Build all binaries
+all: $(MAINS)
+
+# Delete build output
+clean:
+ rm -f -- $(MAINS)
+
+# Executable files
+%: %.cpp $(LIBSRC:=.cpp) $(LIBSRC:=.hpp)
+ $(CXX) $(CXXFLAGS) -o $@ $< $(LIBSRC:=.cpp)
diff --git a/src/third_party/QR-Code-generator/cpp/QrCode.cpp b/src/third_party/QR-Code-generator/cpp/QrCode.cpp
new file mode 100644
index 0000000..75a5473
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrCode.cpp
@@ -0,0 +1,616 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#include <algorithm>
+#include <climits>
+#include <cstddef>
+#include <cstdlib>
+#include <sstream>
+#include <utility>
+#include "BitBuffer.hpp"
+#include "QrCode.hpp"
+
+using std::int8_t;
+using std::uint8_t;
+using std::size_t;
+using std::vector;
+
+
+namespace qrcodegen {
+
+int QrCode::getFormatBits(Ecc ecl) {
+ switch (ecl) {
+ case Ecc::LOW : return 1;
+ case Ecc::MEDIUM : return 0;
+ case Ecc::QUARTILE: return 3;
+ case Ecc::HIGH : return 2;
+ default: throw "Assertion error";
+ }
+}
+
+
+QrCode QrCode::encodeText(const char *text, Ecc ecl) {
+ vector<QrSegment> segs = QrSegment::makeSegments(text);
+ return encodeSegments(segs, ecl);
+}
+
+
+QrCode QrCode::encodeBinary(const vector<uint8_t> &data, Ecc ecl) {
+ vector<QrSegment> segs{QrSegment::makeBytes(data)};
+ return encodeSegments(segs, ecl);
+}
+
+
+QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
+ int minVersion, int maxVersion, int mask, bool boostEcl) {
+ if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7)
+ throw "Invalid value";
+
+ // Find the minimal version number to use
+ int version, dataUsedBits;
+ for (version = minVersion; ; version++) {
+ int dataCapacityBits = getNumDataCodewords(version, ecl) * 8; // Number of data bits available
+ dataUsedBits = QrSegment::getTotalBits(segs, version);
+ if (dataUsedBits != -1 && dataUsedBits <= dataCapacityBits)
+ break; // This version number is found to be suitable
+ if (version >= maxVersion) // All versions in the range could not fit the given data
+ throw "Data too long";
+ }
+ if (dataUsedBits == -1)
+ throw "Assertion error";
+
+ // Increase the error correction level while the data still fits in the current version number
+ for (Ecc newEcl : vector<Ecc>{Ecc::MEDIUM, Ecc::QUARTILE, Ecc::HIGH}) {
+ if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8)
+ ecl = newEcl;
+ }
+
+ // Create the data bit string by concatenating all segments
+ size_t dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
+ BitBuffer bb;
+ for (const QrSegment &seg : segs) {
+ bb.appendBits(seg.getMode().getModeBits(), 4);
+ bb.appendBits(seg.getNumChars(), seg.getMode().numCharCountBits(version));
+ bb.insert(bb.end(), seg.getData().begin(), seg.getData().end());
+ }
+
+ // Add terminator and pad up to a byte if applicable
+ bb.appendBits(0, std::min<size_t>(4, dataCapacityBits - bb.size()));
+ bb.appendBits(0, (8 - bb.size() % 8) % 8);
+
+ // Pad with alternate bytes until data capacity is reached
+ for (uint8_t padByte = 0xEC; bb.size() < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
+ bb.appendBits(padByte, 8);
+ if (bb.size() % 8 != 0)
+ throw "Assertion error";
+
+ // Create the QR Code symbol
+ return QrCode(version, ecl, bb.getBytes(), mask);
+}
+
+
+QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask) :
+ // Initialize fields
+ version(ver),
+ size(MIN_VERSION <= ver && ver <= MAX_VERSION ? ver * 4 + 17 : -1), // Avoid signed overflow undefined behavior
+ errorCorrectionLevel(ecl),
+ modules(size, vector<bool>(size)), // Entirely white grid
+ isFunction(size, vector<bool>(size)) {
+
+ // Check arguments
+ if (ver < MIN_VERSION || ver > MAX_VERSION || mask < -1 || mask > 7)
+ throw "Value out of range";
+
+ // Draw function patterns, draw all codewords, do masking
+ drawFunctionPatterns();
+ const vector<uint8_t> allCodewords = appendErrorCorrection(dataCodewords);
+ drawCodewords(allCodewords);
+ this->mask = handleConstructorMasking(mask);
+}
+
+
+int QrCode::getVersion() const {
+ return version;
+}
+
+
+int QrCode::getSize() const {
+ return size;
+}
+
+
+QrCode::Ecc QrCode::getErrorCorrectionLevel() const {
+ return errorCorrectionLevel;
+}
+
+
+int QrCode::getMask() const {
+ return mask;
+}
+
+
+bool QrCode::getModule(int x, int y) const {
+ return 0 <= x && x < size && 0 <= y && y < size && module(x, y);
+}
+
+
+std::string QrCode::toSvgString(int border) const {
+ if (border < 0)
+ throw "Border must be non-negative";
+ if (border > INT_MAX / 2 || border * 2 > INT_MAX - size)
+ throw "Border too large";
+
+ std::ostringstream sb;
+ sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
+ sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
+ sb << (size + border * 2) << " " << (size + border * 2) << "\" stroke=\"none\">\n";
+ sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
+ sb << "\t<path d=\"";
+ bool head = true;
+ for (int y = -border; y < size + border; y++) {
+ for (int x = -border; x < size + border; x++) {
+ if (getModule(x, y)) {
+ if (head)
+ head = false;
+ else
+ sb << " ";
+ sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
+ }
+ }
+ }
+ sb << "\" fill=\"#000000\"/>\n";
+ sb << "</svg>\n";
+ return sb.str();
+}
+
+
+void QrCode::drawFunctionPatterns() {
+ // Draw horizontal and vertical timing patterns
+ for (int i = 0; i < size; i++) {
+ setFunctionModule(6, i, i % 2 == 0);
+ setFunctionModule(i, 6, i % 2 == 0);
+ }
+
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
+ drawFinderPattern(3, 3);
+ drawFinderPattern(size - 4, 3);
+ drawFinderPattern(3, size - 4);
+
+ // Draw numerous alignment patterns
+ const vector<int> alignPatPos = getAlignmentPatternPositions(version);
+ int numAlign = alignPatPos.size();
+ for (int i = 0; i < numAlign; i++) {
+ for (int j = 0; j < numAlign; j++) {
+ if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0))
+ continue; // Skip the three finder corners
+ else
+ drawAlignmentPattern(alignPatPos.at(i), alignPatPos.at(j));
+ }
+ }
+
+ // Draw configuration data
+ drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
+ drawVersion();
+}
+
+
+void QrCode::drawFormatBits(int mask) {
+ // Calculate error correction code and pack bits
+ int data = getFormatBits(errorCorrectionLevel) << 3 | mask; // errCorrLvl is uint2, mask is uint3
+ int rem = data;
+ for (int i = 0; i < 10; i++)
+ rem = (rem << 1) ^ ((rem >> 9) * 0x537);
+ data = data << 10 | rem;
+ data ^= 0x5412; // uint15
+ if (data >> 15 != 0)
+ throw "Assertion error";
+
+ // Draw first copy
+ for (int i = 0; i <= 5; i++)
+ setFunctionModule(8, i, ((data >> i) & 1) != 0);
+ setFunctionModule(8, 7, ((data >> 6) & 1) != 0);
+ setFunctionModule(8, 8, ((data >> 7) & 1) != 0);
+ setFunctionModule(7, 8, ((data >> 8) & 1) != 0);
+ for (int i = 9; i < 15; i++)
+ setFunctionModule(14 - i, 8, ((data >> i) & 1) != 0);
+
+ // Draw second copy
+ for (int i = 0; i <= 7; i++)
+ setFunctionModule(size - 1 - i, 8, ((data >> i) & 1) != 0);
+ for (int i = 8; i < 15; i++)
+ setFunctionModule(8, size - 15 + i, ((data >> i) & 1) != 0);
+ setFunctionModule(8, size - 8, true);
+}
+
+
+void QrCode::drawVersion() {
+ if (version < 7)
+ return;
+
+ // Calculate error correction code and pack bits
+ int rem = version; // version is uint6, in the range [7, 40]
+ for (int i = 0; i < 12; i++)
+ rem = (rem << 1) ^ ((rem >> 11) * 0x1F25);
+ long data = (long)version << 12 | rem; // uint18
+ if (data >> 18 != 0)
+ throw "Assertion error";
+
+ // Draw two copies
+ for (int i = 0; i < 18; i++) {
+ bool bit = ((data >> i) & 1) != 0;
+ int a = size - 11 + i % 3, b = i / 3;
+ setFunctionModule(a, b, bit);
+ setFunctionModule(b, a, bit);
+ }
+}
+
+
+void QrCode::drawFinderPattern(int x, int y) {
+ for (int i = -4; i <= 4; i++) {
+ for (int j = -4; j <= 4; j++) {
+ int dist = std::max(std::abs(i), std::abs(j)); // Chebyshev/infinity norm
+ int xx = x + j, yy = y + i;
+ if (0 <= xx && xx < size && 0 <= yy && yy < size)
+ setFunctionModule(xx, yy, dist != 2 && dist != 4);
+ }
+ }
+}
+
+
+void QrCode::drawAlignmentPattern(int x, int y) {
+ for (int i = -2; i <= 2; i++) {
+ for (int j = -2; j <= 2; j++)
+ setFunctionModule(x + j, y + i, std::max(std::abs(i), std::abs(j)) != 1);
+ }
+}
+
+
+void QrCode::setFunctionModule(int x, int y, bool isBlack) {
+ modules.at(y).at(x) = isBlack;
+ isFunction.at(y).at(x) = true;
+}
+
+
+bool QrCode::module(int x, int y) const {
+ return modules.at(y).at(x);
+}
+
+
+vector<uint8_t> QrCode::appendErrorCorrection(const vector<uint8_t> &data) const {
+ if (data.size() != static_cast<unsigned int>(getNumDataCodewords(version, errorCorrectionLevel)))
+ throw "Invalid argument";
+
+ // Calculate parameter numbers
+ int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[static_cast<int>(errorCorrectionLevel)][version];
+ int blockEccLen = ECC_CODEWORDS_PER_BLOCK[static_cast<int>(errorCorrectionLevel)][version];
+ int rawCodewords = getNumRawDataModules(version) / 8;
+ int numShortBlocks = numBlocks - rawCodewords % numBlocks;
+ int shortBlockLen = rawCodewords / numBlocks;
+
+ // Split data into blocks and append ECC to each block
+ vector<vector<uint8_t> > blocks;
+ const ReedSolomonGenerator rs(blockEccLen);
+ for (int i = 0, k = 0; i < numBlocks; i++) {
+ vector<uint8_t> dat(data.cbegin() + k, data.cbegin() + (k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1)));
+ k += dat.size();
+ const vector<uint8_t> ecc = rs.getRemainder(dat);
+ if (i < numShortBlocks)
+ dat.push_back(0);
+ dat.insert(dat.end(), ecc.cbegin(), ecc.cend());
+ blocks.push_back(std::move(dat));
+ }
+
+ // Interleave (not concatenate) the bytes from every block into a single sequence
+ vector<uint8_t> result;
+ for (int i = 0; static_cast<unsigned int>(i) < blocks.at(0).size(); i++) {
+ for (int j = 0; static_cast<unsigned int>(j) < blocks.size(); j++) {
+ // Skip the padding byte in short blocks
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
+ result.push_back(blocks.at(j).at(i));
+ }
+ }
+ if (result.size() != static_cast<unsigned int>(rawCodewords))
+ throw "Assertion error";
+ return result;
+}
+
+
+void QrCode::drawCodewords(const vector<uint8_t> &data) {
+ if (data.size() != static_cast<unsigned int>(getNumRawDataModules(version) / 8))
+ throw "Invalid argument";
+
+ size_t i = 0; // Bit index into the data
+ // Do the funny zigzag scan
+ for (int right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
+ if (right == 6)
+ right = 5;
+ for (int vert = 0; vert < size; vert++) { // Vertical counter
+ for (int j = 0; j < 2; j++) {
+ int x = right - j; // Actual x coordinate
+ bool upward = ((right + 1) & 2) == 0;
+ int y = upward ? size - 1 - vert : vert; // Actual y coordinate
+ if (!isFunction.at(y).at(x) && i < data.size() * 8) {
+ modules.at(y).at(x) = ((data.at(i >> 3) >> (7 - (i & 7))) & 1) != 0;
+ i++;
+ }
+ // If there are any remainder bits (0 to 7), they are already
+ // set to 0/false/white when the grid of modules was initialized
+ }
+ }
+ }
+ if (static_cast<unsigned int>(i) != data.size() * 8)
+ throw "Assertion error";
+}
+
+
+void QrCode::applyMask(int mask) {
+ if (mask < 0 || mask > 7)
+ throw "Mask value out of range";
+ for (int y = 0; y < size; y++) {
+ for (int x = 0; x < size; x++) {
+ bool invert;
+ switch (mask) {
+ case 0: invert = (x + y) % 2 == 0; break;
+ case 1: invert = y % 2 == 0; break;
+ case 2: invert = x % 3 == 0; break;
+ case 3: invert = (x + y) % 3 == 0; break;
+ case 4: invert = (x / 3 + y / 2) % 2 == 0; break;
+ case 5: invert = x * y % 2 + x * y % 3 == 0; break;
+ case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
+ case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
+ default: throw "Assertion error";
+ }
+ modules.at(y).at(x) = modules.at(y).at(x) ^ (invert & !isFunction.at(y).at(x));
+ }
+ }
+}
+
+
+int QrCode::handleConstructorMasking(int mask) {
+ if (mask == -1) { // Automatically choose best mask
+ long minPenalty = LONG_MAX;
+ for (int i = 0; i < 8; i++) {
+ drawFormatBits(i);
+ applyMask(i);
+ long penalty = getPenaltyScore();
+ if (penalty < minPenalty) {
+ mask = i;
+ minPenalty = penalty;
+ }
+ applyMask(i); // Undoes the mask due to XOR
+ }
+ }
+ if (mask < 0 || mask > 7)
+ throw "Assertion error";
+ drawFormatBits(mask); // Overwrite old format bits
+ applyMask(mask); // Apply the final choice of mask
+ return mask; // The caller shall assign this value to the final-declared field
+}
+
+
+long QrCode::getPenaltyScore() const {
+ long result = 0;
+
+ // Adjacent modules in row having same color
+ for (int y = 0; y < size; y++) {
+ bool colorX = false;
+ for (int x = 0, runX = -1; x < size; x++) {
+ if (x == 0 || module(x, y) != colorX) {
+ colorX = module(x, y);
+ runX = 1;
+ } else {
+ runX++;
+ if (runX == 5)
+ result += PENALTY_N1;
+ else if (runX > 5)
+ result++;
+ }
+ }
+ }
+ // Adjacent modules in column having same color
+ for (int x = 0; x < size; x++) {
+ bool colorY = false;
+ for (int y = 0, runY = -1; y < size; y++) {
+ if (y == 0 || module(x, y) != colorY) {
+ colorY = module(x, y);
+ runY = 1;
+ } else {
+ runY++;
+ if (runY == 5)
+ result += PENALTY_N1;
+ else if (runY > 5)
+ result++;
+ }
+ }
+ }
+
+ // 2*2 blocks of modules having same color
+ for (int y = 0; y < size - 1; y++) {
+ for (int x = 0; x < size - 1; x++) {
+ bool color = module(x, y);
+ if ( color == module(x + 1, y) &&
+ color == module(x, y + 1) &&
+ color == module(x + 1, y + 1))
+ result += PENALTY_N2;
+ }
+ }
+
+ // Finder-like pattern in rows
+ for (int y = 0; y < size; y++) {
+ for (int x = 0, bits = 0; x < size; x++) {
+ bits = ((bits << 1) & 0x7FF) | (module(x, y) ? 1 : 0);
+ if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
+ result += PENALTY_N3;
+ }
+ }
+ // Finder-like pattern in columns
+ for (int x = 0; x < size; x++) {
+ for (int y = 0, bits = 0; y < size; y++) {
+ bits = ((bits << 1) & 0x7FF) | (module(x, y) ? 1 : 0);
+ if (y >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
+ result += PENALTY_N3;
+ }
+ }
+
+ // Balance of black and white modules
+ int black = 0;
+ for (const vector<bool> &row : modules) {
+ for (bool color : row) {
+ if (color)
+ black++;
+ }
+ }
+ int total = size * size;
+ // Find smallest k such that (45-5k)% <= dark/total <= (55+5k)%
+ for (int k = 0; black*20L < (9L-k)*total || black*20L > (11L+k)*total; k++)
+ result += PENALTY_N4;
+ return result;
+}
+
+
+vector<int> QrCode::getAlignmentPatternPositions(int ver) {
+ if (ver < MIN_VERSION || ver > MAX_VERSION)
+ throw "Version number out of range";
+ else if (ver == 1)
+ return vector<int>();
+ else {
+ int numAlign = ver / 7 + 2;
+ int step;
+ if (ver != 32) {
+ // ceil((size - 13) / (2*numAlign - 2)) * 2
+ step = (ver * 4 + numAlign * 2 + 1) / (2 * numAlign - 2) * 2;
+ } else // C-C-C-Combo breaker!
+ step = 26;
+
+ vector<int> result;
+ for (int i = 0, pos = ver * 4 + 10; i < numAlign - 1; i++, pos -= step)
+ result.insert(result.begin(), pos);
+ result.insert(result.begin(), 6);
+ return result;
+ }
+}
+
+
+int QrCode::getNumRawDataModules(int ver) {
+ if (ver < MIN_VERSION || ver > MAX_VERSION)
+ throw "Version number out of range";
+ int result = (16 * ver + 128) * ver + 64;
+ if (ver >= 2) {
+ int numAlign = ver / 7 + 2;
+ result -= (25 * numAlign - 10) * numAlign - 55;
+ if (ver >= 7)
+ result -= 18 * 2; // Subtract version information
+ }
+ return result;
+}
+
+
+int QrCode::getNumDataCodewords(int ver, Ecc ecl) {
+ if (ver < MIN_VERSION || ver > MAX_VERSION)
+ throw "Version number out of range";
+ return getNumRawDataModules(ver) / 8
+ - ECC_CODEWORDS_PER_BLOCK[static_cast<int>(ecl)][ver]
+ * NUM_ERROR_CORRECTION_BLOCKS[static_cast<int>(ecl)][ver];
+}
+
+
+/*---- Tables of constants ----*/
+
+const int QrCode::PENALTY_N1 = 3;
+const int QrCode::PENALTY_N2 = 3;
+const int QrCode::PENALTY_N3 = 40;
+const int QrCode::PENALTY_N4 = 10;
+
+
+const int8_t QrCode::ECC_CODEWORDS_PER_BLOCK[4][41] = {
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
+ {-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Low
+ {-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28}, // Medium
+ {-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // Quartile
+ {-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}, // High
+};
+
+const int8_t QrCode::NUM_ERROR_CORRECTION_BLOCKS[4][41] = {
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
+ {-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25}, // Low
+ {-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49}, // Medium
+ {-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68}, // Quartile
+ {-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81}, // High
+};
+
+
+QrCode::ReedSolomonGenerator::ReedSolomonGenerator(int degree) :
+ coefficients() {
+ if (degree < 1 || degree > 255)
+ throw "Degree out of range";
+
+ // Start with the monomial x^0
+ coefficients.resize(degree);
+ coefficients.at(degree - 1) = 1;
+
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
+ // drop the highest term, and store the rest of the coefficients in order of descending powers.
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
+ uint8_t root = 1;
+ for (int i = 0; i < degree; i++) {
+ // Multiply the current product by (x - r^i)
+ for (size_t j = 0; j < coefficients.size(); j++) {
+ coefficients.at(j) = multiply(coefficients.at(j), root);
+ if (j + 1 < coefficients.size())
+ coefficients.at(j) ^= coefficients.at(j + 1);
+ }
+ root = multiply(root, 0x02);
+ }
+}
+
+
+vector<uint8_t> QrCode::ReedSolomonGenerator::getRemainder(const vector<uint8_t> &data) const {
+ // Compute the remainder by performing polynomial division
+ vector<uint8_t> result(coefficients.size());
+ for (uint8_t b : data) {
+ uint8_t factor = b ^ result.at(0);
+ result.erase(result.begin());
+ result.push_back(0);
+ for (size_t j = 0; j < result.size(); j++)
+ result.at(j) ^= multiply(coefficients.at(j), factor);
+ }
+ return result;
+}
+
+
+uint8_t QrCode::ReedSolomonGenerator::multiply(uint8_t x, uint8_t y) {
+ // Russian peasant multiplication
+ int z = 0;
+ for (int i = 7; i >= 0; i--) {
+ z = (z << 1) ^ ((z >> 7) * 0x11D);
+ z ^= ((y >> i) & 1) * x;
+ }
+ if (z >> 8 != 0)
+ throw "Assertion error";
+ return static_cast<uint8_t>(z);
+}
+
+}
diff --git a/src/third_party/QR-Code-generator/cpp/QrCode.hpp b/src/third_party/QR-Code-generator/cpp/QrCode.hpp
new file mode 100644
index 0000000..14a3f61
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrCode.hpp
@@ -0,0 +1,306 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <string>
+#include <vector>
+#include "QrSegment.hpp"
+
+
+namespace qrcodegen {
+
+/*
+ * Represents an immutable square grid of black and white cells for a QR Code symbol, and
+ * provides static functions to create a QR Code from user-supplied textual or binary data.
+ * This class covers the QR Code model 2 specification, supporting all versions (sizes)
+ * from 1 to 40, all 4 error correction levels, and only 3 character encoding modes.
+ */
+class QrCode final {
+
+ /*---- Public helper enumeration ----*/
+
+ /*
+ * Represents the error correction level used in a QR Code symbol.
+ */
+ public: enum class Ecc {
+ // Constants declared in ascending order of error protection.
+ LOW = 0, MEDIUM = 1, QUARTILE = 2, HIGH = 3
+ };
+
+
+ // Returns a value in the range 0 to 3 (unsigned 2-bit integer).
+ private: static int getFormatBits(Ecc ecl);
+
+
+
+ /*---- Public static factory functions ----*/
+
+ /*
+ * Returns a QR Code symbol representing the specified Unicode text string at the specified error correction level.
+ * As a conservative upper bound, this function is guaranteed to succeed for strings that have 2953 or fewer
+ * UTF-8 code units (not Unicode code points) if the low error correction level is used. The smallest possible
+ * QR Code version is automatically chosen for the output. The ECC level of the result may be higher than
+ * the ecl argument if it can be done without increasing the version.
+ */
+ public: static QrCode encodeText(const char *text, Ecc ecl);
+
+
+ /*
+ * Returns a QR Code symbol representing the given binary data string at the given error correction level.
+ * This function always encodes using the binary segment mode, not any text mode. The maximum number of
+ * bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
+ * The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
+ */
+ public: static QrCode encodeBinary(const std::vector<std::uint8_t> &data, Ecc ecl);
+
+
+ /*
+ * Returns a QR Code symbol representing the given data segments with the given encoding parameters.
+ * The smallest possible QR Code version within the given range is automatically chosen for the output.
+ * This function allows the user to create a custom sequence of segments that switches
+ * between modes (such as alphanumeric and binary) to encode text more efficiently.
+ * This function is considered to be lower level than simply encoding text or binary data.
+ */
+ public: static QrCode encodeSegments(const std::vector<QrSegment> &segs, Ecc ecl,
+ int minVersion=1, int maxVersion=40, int mask=-1, bool boostEcl=true); // All optional parameters
+
+
+
+ /*---- Public constants ----*/
+
+ public: static constexpr int MIN_VERSION = 1;
+ public: static constexpr int MAX_VERSION = 40;
+
+
+
+ /*---- Instance fields ----*/
+
+ // Immutable scalar parameters
+
+ /* This QR Code symbol's version number, which is always between 1 and 40 (inclusive). */
+ private: int version;
+
+ /* The width and height of this QR Code symbol, measured in modules.
+ * Always equal to version × 4 + 17, in the range 21 to 177. */
+ private: int size;
+
+ /* The error correction level used in this QR Code symbol. */
+ private: Ecc errorCorrectionLevel;
+
+ /* The mask pattern used in this QR Code symbol, in the range 0 to 7 (i.e. unsigned 3-bit integer).
+ * Note that even if a constructor was called with automatic masking requested
+ * (mask = -1), the resulting object will still have a mask value between 0 and 7. */
+ private: int mask;
+
+ // Private grids of modules/pixels (conceptually immutable)
+ private: std::vector<std::vector<bool> > modules; // The modules of this QR Code symbol (false = white, true = black)
+ private: std::vector<std::vector<bool> > isFunction; // Indicates function modules that are not subjected to masking
+
+
+
+ /*---- Constructors ----*/
+
+ /*
+ * Creates a new QR Code symbol with the given version number, error correction level, binary data array,
+ * and mask number. This is a cumbersome low-level constructor that should not be invoked directly by the user.
+ * To go one level up, see the encodeSegments() function.
+ */
+ public: QrCode(int ver, Ecc ecl, const std::vector<std::uint8_t> &dataCodewords, int mask);
+
+
+
+ /*---- Public instance methods ----*/
+
+ public: int getVersion() const;
+
+
+ public: int getSize() const;
+
+
+ public: Ecc getErrorCorrectionLevel() const;
+
+
+ public: int getMask() const;
+
+
+ /*
+ * Returns the color of the module (pixel) at the given coordinates, which is either
+ * false for white or true for black. The top left corner has the coordinates (x=0, y=0).
+ * If the given coordinates are out of bounds, then false (white) is returned.
+ */
+ public: bool getModule(int x, int y) const;
+
+
+ /*
+ * Based on the given number of border modules to add as padding, this returns a
+ * string whose contents represents an SVG XML file that depicts this QR Code symbol.
+ * Note that Unix newlines (\n) are always used, regardless of the platform.
+ */
+ public: std::string toSvgString(int border) const;
+
+
+
+ /*---- Private helper methods for constructor: Drawing function modules ----*/
+
+ private: void drawFunctionPatterns();
+
+
+ // Draws two copies of the format bits (with its own error correction code)
+ // based on the given mask and this object's error correction level field.
+ private: void drawFormatBits(int mask);
+
+
+ // Draws two copies of the version bits (with its own error correction code),
+ // based on this object's version field (which only has an effect for 7 <= version <= 40).
+ private: void drawVersion();
+
+
+ // Draws a 9*9 finder pattern including the border separator, with the center module at (x, y).
+ private: void drawFinderPattern(int x, int y);
+
+
+ // Draws a 5*5 alignment pattern, with the center module at (x, y).
+ private: void drawAlignmentPattern(int x, int y);
+
+
+ // Sets the color of a module and marks it as a function module.
+ // Only used by the constructor. Coordinates must be in range.
+ private: void setFunctionModule(int x, int y, bool isBlack);
+
+
+ // Returns the color of the module at the given coordinates, which must be in range.
+ private: bool module(int x, int y) const;
+
+
+ /*---- Private helper methods for constructor: Codewords and masking ----*/
+
+ // Returns a new byte string representing the given data with the appropriate error correction
+ // codewords appended to it, based on this object's version and error correction level.
+ private: std::vector<std::uint8_t> appendErrorCorrection(const std::vector<std::uint8_t> &data) const;
+
+
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
+ // data area of this QR Code symbol. Function modules need to be marked off before this is called.
+ private: void drawCodewords(const std::vector<std::uint8_t> &data);
+
+
+ // XORs the data modules in this QR Code with the given mask pattern. Due to XOR's mathematical
+ // properties, calling applyMask(m) twice with the same value is equivalent to no change at all.
+ // This means it is possible to apply a mask, undo it, and try another mask. Note that a final
+ // well-formed QR Code symbol needs exactly one mask applied (not zero, not two, etc.).
+ private: void applyMask(int mask);
+
+
+ // A messy helper function for the constructors. This QR Code must be in an unmasked state when this
+ // method is called. The given argument is the requested mask, which is -1 for auto or 0 to 7 for fixed.
+ // This method applies and returns the actual mask chosen, from 0 to 7.
+ private: int handleConstructorMasking(int mask);
+
+
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
+ private: long getPenaltyScore() const;
+
+
+
+ /*---- Private static helper functions ----*/
+
+ // Returns a set of positions of the alignment patterns in ascending order. These positions are
+ // used on both the x and y axes. Each value in the resulting array is in the range [0, 177).
+ // This stateless pure function could be implemented as table of 40 variable-length lists of unsigned bytes.
+ private: static std::vector<int> getAlignmentPatternPositions(int ver);
+
+
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
+ private: static int getNumRawDataModules(int ver);
+
+
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
+ private: static int getNumDataCodewords(int ver, Ecc ecl);
+
+
+ /*---- Private tables of constants ----*/
+
+ // For use in getPenaltyScore(), when evaluating which mask is best.
+ private: static const int PENALTY_N1;
+ private: static const int PENALTY_N2;
+ private: static const int PENALTY_N3;
+ private: static const int PENALTY_N4;
+
+ private: static const std::int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
+ private: static const std::int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
+
+
+
+ /*---- Private helper class ----*/
+
+ /*
+ * Computes the Reed-Solomon error correction codewords for a sequence of data codewords
+ * at a given degree. Objects are immutable, and the state only depends on the degree.
+ * This class exists because each data block in a QR Code shares the same the divisor polynomial.
+ */
+ private: class ReedSolomonGenerator final {
+
+ /*-- Immutable field --*/
+
+ // Coefficients of the divisor polynomial, stored from highest to lowest power, excluding the leading term which
+ // is always 1. For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}.
+ private: std::vector<std::uint8_t> coefficients;
+
+
+ /*-- Constructor --*/
+
+ /*
+ * Creates a Reed-Solomon ECC generator for the given degree. This could be implemented
+ * as a lookup table over all possible parameter values, instead of as an algorithm.
+ */
+ public: explicit ReedSolomonGenerator(int degree);
+
+
+ /*-- Method --*/
+
+ /*
+ * Computes and returns the Reed-Solomon error correction codewords for the given
+ * sequence of data codewords. The returned object is always a new byte array.
+ * This method does not alter this object's state (because it is immutable).
+ */
+ public: std::vector<std::uint8_t> getRemainder(const std::vector<std::uint8_t> &data) const;
+
+
+ /*-- Static function --*/
+
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D).
+ // All inputs are valid. This could be implemented as a 256*256 lookup table.
+ private: static std::uint8_t multiply(std::uint8_t x, std::uint8_t y);
+
+ };
+
+};
+
+}
diff --git a/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorDemo.cpp b/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorDemo.cpp
new file mode 100644
index 0000000..5c78b51
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorDemo.cpp
@@ -0,0 +1,199 @@
+/*
+ * QR Code generator demo (C++)
+ *
+ * Run this command-line program with no arguments. The program computes a bunch of demonstration
+ * QR Codes and prints them to the console. Also, the SVG code for one QR Code is printed as a sample.
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <string>
+#include <vector>
+#include "BitBuffer.hpp"
+#include "QrCode.hpp"
+
+using std::uint8_t;
+using qrcodegen::QrCode;
+using qrcodegen::QrSegment;
+
+
+// Function prototypes
+static void doBasicDemo();
+static void doVarietyDemo();
+static void doSegmentDemo();
+static void doMaskDemo();
+static void printQr(const QrCode &qr);
+
+
+// The main application program.
+int main() {
+ doBasicDemo();
+ doVarietyDemo();
+ doSegmentDemo();
+ doMaskDemo();
+ return EXIT_SUCCESS;
+}
+
+
+
+/*---- Demo suite ----*/
+
+// Creates a single QR Code, then prints it to the console.
+static void doBasicDemo() {
+ const char *text = "Hello, world!"; // User-supplied text
+ const QrCode::Ecc errCorLvl = QrCode::Ecc::LOW; // Error correction level
+
+ // Make and print the QR Code symbol
+ const QrCode qr = QrCode::encodeText(text, errCorLvl);
+ printQr(qr);
+ std::cout << qr.toSvgString(4) << std::endl;
+}
+
+
+// Creates a variety of QR Codes that exercise different features of the library, and prints each one to the console.
+static void doVarietyDemo() {
+ // Numeric mode encoding (3.33 bits per digit)
+ const QrCode qr1 = QrCode::encodeText("314159265358979323846264338327950288419716939937510", QrCode::Ecc::MEDIUM);
+ printQr(qr1);
+
+ // Alphanumeric mode encoding (5.5 bits per character)
+ const QrCode qr2 = QrCode::encodeText("DOLLAR-AMOUNT:$39.87 PERCENTAGE:100.00% OPERATIONS:+-*/", QrCode::Ecc::HIGH);
+ printQr(qr2);
+
+ // Unicode text as UTF-8
+ const QrCode qr3 = QrCode::encodeText("\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1wa\xE3\x80\x81\xE4\xB8\x96\xE7\x95\x8C\xEF\xBC\x81\x20\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4", QrCode::Ecc::QUARTILE);
+ printQr(qr3);
+
+ // Moderately large QR Code using longer text (from Lewis Carroll's Alice in Wonderland)
+ const QrCode qr4 = QrCode::encodeText(
+ "Alice was beginning to get very tired of sitting by her sister on the bank, "
+ "and of having nothing to do: once or twice she had peeped into the book her sister was reading, "
+ "but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice "
+ "'without pictures or conversations?' So she was considering in her own mind (as well as she could, "
+ "for the hot day made her feel very sleepy and stupid), whether the pleasure of making a "
+ "daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly "
+ "a White Rabbit with pink eyes ran close by her.", QrCode::Ecc::HIGH);
+ printQr(qr4);
+}
+
+
+// Creates QR Codes with manually specified segments for better compactness.
+static void doSegmentDemo() {
+ // Illustration "silver"
+ const char *silver0 = "THE SQUARE ROOT OF 2 IS 1.";
+ const char *silver1 = "41421356237309504880168872420969807856967187537694807317667973799";
+ const QrCode qr0 = QrCode::encodeText(
+ (std::string(silver0) + silver1).c_str(),
+ QrCode::Ecc::LOW);
+ printQr(qr0);
+
+ const QrCode qr1 = QrCode::encodeSegments(
+ {QrSegment::makeAlphanumeric(silver0), QrSegment::makeNumeric(silver1)},
+ QrCode::Ecc::LOW);
+ printQr(qr1);
+
+ // Illustration "golden"
+ const char *golden0 = "Golden ratio \xCF\x86 = 1.";
+ const char *golden1 = "6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374";
+ const char *golden2 = "......";
+ const QrCode qr2 = QrCode::encodeText(
+ (std::string(golden0) + golden1 + golden2).c_str(),
+ QrCode::Ecc::LOW);
+ printQr(qr2);
+
+ std::vector<uint8_t> bytes(golden0, golden0 + std::strlen(golden0));
+ const QrCode qr3 = QrCode::encodeSegments(
+ {QrSegment::makeBytes(bytes), QrSegment::makeNumeric(golden1), QrSegment::makeAlphanumeric(golden2)},
+ QrCode::Ecc::LOW);
+ printQr(qr3);
+
+ // Illustration "Madoka": kanji, kana, Greek, Cyrillic, full-width Latin characters
+ const char *madoka = // Encoded in UTF-8
+ "\xE3\x80\x8C\xE9\xAD\x94\xE6\xB3\x95\xE5"
+ "\xB0\x91\xE5\xA5\xB3\xE3\x81\xBE\xE3\x81"
+ "\xA9\xE3\x81\x8B\xE2\x98\x86\xE3\x83\x9E"
+ "\xE3\x82\xAE\xE3\x82\xAB\xE3\x80\x8D\xE3"
+ "\x81\xA3\xE3\x81\xA6\xE3\x80\x81\xE3\x80"
+ "\x80\xD0\x98\xD0\x90\xD0\x98\xE3\x80\x80"
+ "\xEF\xBD\x84\xEF\xBD\x85\xEF\xBD\x93\xEF"
+ "\xBD\x95\xE3\x80\x80\xCE\xBA\xCE\xB1\xEF"
+ "\xBC\x9F";
+ const QrCode qr4 = QrCode::encodeText(madoka, QrCode::Ecc::LOW);
+ printQr(qr4);
+
+ const std::vector<int> kanjiChars{ // Kanji mode encoding (13 bits per character)
+ 0x0035, 0x1002, 0x0FC0, 0x0AED, 0x0AD7,
+ 0x015C, 0x0147, 0x0129, 0x0059, 0x01BD,
+ 0x018D, 0x018A, 0x0036, 0x0141, 0x0144,
+ 0x0001, 0x0000, 0x0249, 0x0240, 0x0249,
+ 0x0000, 0x0104, 0x0105, 0x0113, 0x0115,
+ 0x0000, 0x0208, 0x01FF, 0x0008,
+ };
+ qrcodegen::BitBuffer bb;
+ for (int c : kanjiChars)
+ bb.appendBits(c, 13);
+ const QrCode qr5 = QrCode::encodeSegments(
+ {QrSegment(QrSegment::Mode::KANJI, kanjiChars.size(), bb)},
+ QrCode::Ecc::LOW);
+ printQr(qr5);
+}
+
+
+// Creates QR Codes with the same size and contents but different mask patterns.
+static void doMaskDemo() {
+ // Project Nayuki URL
+ std::vector<QrSegment> segs0 = QrSegment::makeSegments("https://www.nayuki.io/");
+ printQr(QrCode::encodeSegments(segs0, QrCode::Ecc::HIGH, QrCode::MIN_VERSION, QrCode::MAX_VERSION, -1, true)); // Automatic mask
+ printQr(QrCode::encodeSegments(segs0, QrCode::Ecc::HIGH, QrCode::MIN_VERSION, QrCode::MAX_VERSION, 3, true)); // Force mask 3
+
+ // Chinese text as UTF-8
+ std::vector<QrSegment> segs1 = QrSegment::makeSegments(
+ "\xE7\xB6\xAD\xE5\x9F\xBA\xE7\x99\xBE\xE7\xA7\x91\xEF\xBC\x88\x57\x69\x6B\x69\x70"
+ "\x65\x64\x69\x61\xEF\xBC\x8C\xE8\x81\x86\xE8\x81\xBD\x69\x2F\xCB\x8C\x77\xC9\xAA"
+ "\x6B\xE1\xB5\xBB\xCB\x88\x70\x69\xCB\x90\x64\x69\x2E\xC9\x99\x2F\xEF\xBC\x89\xE6"
+ "\x98\xAF\xE4\xB8\x80\xE5\x80\x8B\xE8\x87\xAA\xE7\x94\xB1\xE5\x85\xA7\xE5\xAE\xB9"
+ "\xE3\x80\x81\xE5\x85\xAC\xE9\x96\x8B\xE7\xB7\xA8\xE8\xBC\xAF\xE4\xB8\x94\xE5\xA4"
+ "\x9A\xE8\xAA\x9E\xE8\xA8\x80\xE7\x9A\x84\xE7\xB6\xB2\xE8\xB7\xAF\xE7\x99\xBE\xE7"
+ "\xA7\x91\xE5\x85\xA8\xE6\x9B\xB8\xE5\x8D\x94\xE4\xBD\x9C\xE8\xA8\x88\xE7\x95\xAB");
+ printQr(QrCode::encodeSegments(segs1, QrCode::Ecc::MEDIUM, QrCode::MIN_VERSION, QrCode::MAX_VERSION, 0, true)); // Force mask 0
+ printQr(QrCode::encodeSegments(segs1, QrCode::Ecc::MEDIUM, QrCode::MIN_VERSION, QrCode::MAX_VERSION, 1, true)); // Force mask 1
+ printQr(QrCode::encodeSegments(segs1, QrCode::Ecc::MEDIUM, QrCode::MIN_VERSION, QrCode::MAX_VERSION, 5, true)); // Force mask 5
+ printQr(QrCode::encodeSegments(segs1, QrCode::Ecc::MEDIUM, QrCode::MIN_VERSION, QrCode::MAX_VERSION, 7, true)); // Force mask 7
+}
+
+
+
+/*---- Utilities ----*/
+
+// Prints the given QR Code to the console.
+static void printQr(const QrCode &qr) {
+ int border = 4;
+ for (int y = -border; y < qr.getSize() + border; y++) {
+ for (int x = -border; x < qr.getSize() + border; x++) {
+ std::cout << (qr.getModule(x, y) ? "##" : " ");
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+}
diff --git a/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorWorker.cpp b/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorWorker.cpp
new file mode 100644
index 0000000..2e14607
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrCodeGeneratorWorker.cpp
@@ -0,0 +1,104 @@
+/*
+ * QR Code generator test worker (C++)
+ *
+ * This program reads data and encoding parameters from standard input and writes
+ * QR Code bitmaps to standard output. The I/O format is one integer per line.
+ * Run with no command line arguments. The program is intended for automated
+ * batch testing of end-to-end functionality of this QR Code generator library.
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <vector>
+#include "QrCode.hpp"
+
+using qrcodegen::QrCode;
+using qrcodegen::QrSegment;
+
+
+static const std::vector<QrCode::Ecc> ECC_LEVELS{
+ QrCode::Ecc::LOW,
+ QrCode::Ecc::MEDIUM,
+ QrCode::Ecc::QUARTILE,
+ QrCode::Ecc::HIGH,
+};
+
+
+int main() {
+ while (true) {
+
+ // Read data length or exit
+ int length;
+ std::cin >> length;
+ if (length == -1)
+ break;
+
+ // Read data bytes
+ bool isAscii = true;
+ std::vector<uint8_t> data;
+ for (int i = 0; i < length; i++) {
+ int b;
+ std::cin >> b;
+ data.push_back(static_cast<uint8_t>(b));
+ isAscii &= 0 < b && b < 128;
+ }
+
+ // Read encoding parameters
+ int errCorLvl, minVersion, maxVersion, mask, boostEcl;
+ std::cin >> errCorLvl;
+ std::cin >> minVersion;
+ std::cin >> maxVersion;
+ std::cin >> mask;
+ std::cin >> boostEcl;
+
+ // Make list of segments
+ std::vector<QrSegment> segs;
+ if (isAscii) {
+ std::vector<char> text(data.cbegin(), data.cend());
+ text.push_back('\0');
+ segs = QrSegment::makeSegments(text.data());
+ } else
+ segs.push_back(QrSegment::makeBytes(data));
+
+ try { // Try to make QR Code symbol
+ const QrCode qr = QrCode::encodeSegments(segs,
+ ECC_LEVELS.at(errCorLvl), minVersion, maxVersion, mask, boostEcl == 1);
+ // Print grid of modules
+ std::cout << qr.getVersion() << std::endl;
+ for (int y = 0; y < qr.getSize(); y++) {
+ for (int x = 0; x < qr.getSize(); x++)
+ std::cout << (qr.getModule(x, y) ? 1 : 0) << std::endl;
+ }
+
+ } catch (const char *msg) {
+ if (strcmp(msg, "Data too long") != 0) {
+ std::cerr << msg << std::endl;
+ return EXIT_FAILURE;
+ }
+ std::cout << -1 << std::endl;
+ }
+ std::cout << std::flush;
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/src/third_party/QR-Code-generator/cpp/QrSegment.cpp b/src/third_party/QR-Code-generator/cpp/QrSegment.cpp
new file mode 100644
index 0000000..f711461
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrSegment.cpp
@@ -0,0 +1,228 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#include <climits>
+#include <cstring>
+#include <utility>
+#include "QrSegment.hpp"
+
+using std::uint8_t;
+using std::vector;
+
+
+namespace qrcodegen {
+
+QrSegment::Mode::Mode(int mode, int cc0, int cc1, int cc2) :
+ modeBits(mode) {
+ numBitsCharCount[0] = cc0;
+ numBitsCharCount[1] = cc1;
+ numBitsCharCount[2] = cc2;
+}
+
+
+int QrSegment::Mode::getModeBits() const {
+ return modeBits;
+}
+
+
+int QrSegment::Mode::numCharCountBits(int ver) const {
+ if ( 1 <= ver && ver <= 9) return numBitsCharCount[0];
+ else if (10 <= ver && ver <= 26) return numBitsCharCount[1];
+ else if (27 <= ver && ver <= 40) return numBitsCharCount[2];
+ else throw "Version number out of range";
+}
+
+
+const QrSegment::Mode QrSegment::Mode::NUMERIC (0x1, 10, 12, 14);
+const QrSegment::Mode QrSegment::Mode::ALPHANUMERIC(0x2, 9, 11, 13);
+const QrSegment::Mode QrSegment::Mode::BYTE (0x4, 8, 16, 16);
+const QrSegment::Mode QrSegment::Mode::KANJI (0x8, 8, 10, 12);
+const QrSegment::Mode QrSegment::Mode::ECI (0x7, 0, 0, 0);
+
+
+
+QrSegment QrSegment::makeBytes(const vector<uint8_t> &data) {
+ if (data.size() > INT_MAX)
+ throw "Data too long";
+ BitBuffer bb;
+ for (uint8_t b : data)
+ bb.appendBits(b, 8);
+ return QrSegment(Mode::BYTE, static_cast<int>(data.size()), std::move(bb));
+}
+
+
+QrSegment QrSegment::makeNumeric(const char *digits) {
+ BitBuffer bb;
+ int accumData = 0;
+ int accumCount = 0;
+ int charCount = 0;
+ for (; *digits != '\0'; digits++, charCount++) {
+ char c = *digits;
+ if (c < '0' || c > '9')
+ throw "String contains non-numeric characters";
+ accumData = accumData * 10 + (c - '0');
+ accumCount++;
+ if (accumCount == 3) {
+ bb.appendBits(accumData, 10);
+ accumData = 0;
+ accumCount = 0;
+ }
+ }
+ if (accumCount > 0) // 1 or 2 digits remaining
+ bb.appendBits(accumData, accumCount * 3 + 1);
+ return QrSegment(Mode::NUMERIC, charCount, std::move(bb));
+}
+
+
+QrSegment QrSegment::makeAlphanumeric(const char *text) {
+ BitBuffer bb;
+ int accumData = 0;
+ int accumCount = 0;
+ int charCount = 0;
+ for (; *text != '\0'; text++, charCount++) {
+ const char *temp = std::strchr(ALPHANUMERIC_CHARSET, *text);
+ if (temp == nullptr)
+ throw "String contains unencodable characters in alphanumeric mode";
+ accumData = accumData * 45 + (temp - ALPHANUMERIC_CHARSET);
+ accumCount++;
+ if (accumCount == 2) {
+ bb.appendBits(accumData, 11);
+ accumData = 0;
+ accumCount = 0;
+ }
+ }
+ if (accumCount > 0) // 1 character remaining
+ bb.appendBits(accumData, 6);
+ return QrSegment(Mode::ALPHANUMERIC, charCount, std::move(bb));
+}
+
+
+vector<QrSegment> QrSegment::makeSegments(const char *text) {
+ // Select the most efficient segment encoding automatically
+ vector<QrSegment> result;
+ if (*text == '\0'); // Leave result empty
+ else if (isNumeric(text))
+ result.push_back(makeNumeric(text));
+ else if (isAlphanumeric(text))
+ result.push_back(makeAlphanumeric(text));
+ else {
+ vector<uint8_t> bytes;
+ for (; *text != '\0'; text++)
+ bytes.push_back(static_cast<uint8_t>(*text));
+ result.push_back(makeBytes(bytes));
+ }
+ return result;
+}
+
+
+QrSegment QrSegment::makeEci(long assignVal) {
+ BitBuffer bb;
+ if (0 <= assignVal && assignVal < (1 << 7))
+ bb.appendBits(assignVal, 8);
+ else if ((1 << 7) <= assignVal && assignVal < (1 << 14)) {
+ bb.appendBits(2, 2);
+ bb.appendBits(assignVal, 14);
+ } else if ((1 << 14) <= assignVal && assignVal < 1000000L) {
+ bb.appendBits(6, 3);
+ bb.appendBits(assignVal, 21);
+ } else
+ throw "ECI assignment value out of range";
+ return QrSegment(Mode::ECI, 0, std::move(bb));
+}
+
+
+QrSegment::QrSegment(Mode md, int numCh, const std::vector<bool> &dt) :
+ mode(md),
+ numChars(numCh),
+ data(dt) {
+ if (numCh < 0)
+ throw "Invalid value";
+}
+
+
+QrSegment::QrSegment(Mode md, int numCh, std::vector<bool> &&dt) :
+ mode(md),
+ numChars(numCh),
+ data(std::move(dt)) {
+ if (numCh < 0)
+ throw "Invalid value";
+}
+
+
+int QrSegment::getTotalBits(const vector<QrSegment> &segs, int version) {
+ if (version < 1 || version > 40)
+ throw "Version number out of range";
+ int result = 0;
+ for (const QrSegment &seg : segs) {
+ int ccbits = seg.mode.numCharCountBits(version);
+ // Fail if segment length value doesn't fit in the length field's bit-width
+ if (seg.numChars >= (1L << ccbits))
+ return -1;
+ if (4 + ccbits > INT_MAX - result)
+ return -1;
+ result += 4 + ccbits;
+ if (seg.data.size() > static_cast<unsigned int>(INT_MAX - result))
+ return -1;
+ result += static_cast<int>(seg.data.size());
+ }
+ return result;
+}
+
+
+bool QrSegment::isAlphanumeric(const char *text) {
+ for (; *text != '\0'; text++) {
+ if (std::strchr(ALPHANUMERIC_CHARSET, *text) == nullptr)
+ return false;
+ }
+ return true;
+}
+
+
+bool QrSegment::isNumeric(const char *text) {
+ for (; *text != '\0'; text++) {
+ char c = *text;
+ if (c < '0' || c > '9')
+ return false;
+ }
+ return true;
+}
+
+
+QrSegment::Mode QrSegment::getMode() const {
+ return mode;
+}
+
+
+int QrSegment::getNumChars() const {
+ return numChars;
+}
+
+
+const std::vector<bool> &QrSegment::getData() const {
+ return data;
+}
+
+
+const char *QrSegment::ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
+
+}
diff --git a/src/third_party/QR-Code-generator/cpp/QrSegment.hpp b/src/third_party/QR-Code-generator/cpp/QrSegment.hpp
new file mode 100644
index 0000000..2b9eb66
--- /dev/null
+++ b/src/third_party/QR-Code-generator/cpp/QrSegment.hpp
@@ -0,0 +1,186 @@
+/*
+ * QR Code generator library (C++)
+ *
+ * Copyright (c) Project Nayuki. (MIT License)
+ * https://www.nayuki.io/page/qr-code-generator-library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ * - The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * - The Software is provided "as is", without warranty of any kind, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. In no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the Software or the use or other dealings in the
+ * Software.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <vector>
+#include "BitBuffer.hpp"
+
+
+namespace qrcodegen {
+
+/*
+ * Represents a character string to be encoded in a QR Code symbol. Each segment has
+ * a mode, and a sequence of characters that is already encoded as a sequence of bits.
+ * Instances of this class are immutable.
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
+ */
+class QrSegment final {
+
+ /*---- Public helper enumeration ----*/
+
+ /*
+ * The mode field of a segment. Immutable. Provides methods to retrieve closely related values.
+ */
+ public: class Mode final {
+
+ /*-- Constants --*/
+
+ public: static const Mode NUMERIC;
+ public: static const Mode ALPHANUMERIC;
+ public: static const Mode BYTE;
+ public: static const Mode KANJI;
+ public: static const Mode ECI;
+
+
+ /*-- Fields --*/
+
+ private: int modeBits;
+
+ private: int numBitsCharCount[3];
+
+
+ /*-- Constructor --*/
+
+ private: Mode(int mode, int cc0, int cc1, int cc2);
+
+
+ /*-- Methods --*/
+
+ /*
+ * (Package-private) Returns the mode indicator bits, which is an unsigned 4-bit value (range 0 to 15).
+ */
+ public: int getModeBits() const;
+
+ /*
+ * (Package-private) Returns the bit width of the segment character count field for this mode object at the given version number.
+ */
+ public: int numCharCountBits(int ver) const;
+
+ };
+
+
+
+ /*---- Public static factory functions ----*/
+
+ /*
+ * Returns a segment representing the given binary data encoded in byte mode.
+ */
+ public: static QrSegment makeBytes(const std::vector<std::uint8_t> &data);
+
+
+ /*
+ * Returns a segment representing the given string of decimal digits encoded in numeric mode.
+ */
+ public: static QrSegment makeNumeric(const char *digits);
+
+
+ /*
+ * Returns a segment representing the given text string encoded in alphanumeric mode.
+ * The characters allowed are: 0 to 9, A to Z (uppercase only), space,
+ * dollar, percent, asterisk, plus, hyphen, period, slash, colon.
+ */
+ public: static QrSegment makeAlphanumeric(const char *text);
+
+
+ /*
+ * Returns a list of zero or more segments to represent the given text string.
+ * The result may use various segment modes and switch modes to optimize the length of the bit stream.
+ */
+ public: static std::vector<QrSegment> makeSegments(const char *text);
+
+
+ /*
+ * Returns a segment representing an Extended Channel Interpretation
+ * (ECI) designator with the given assignment value.
+ */
+ public: static QrSegment makeEci(long assignVal);
+
+
+ /*---- Public static helper functions ----*/
+
+ /*
+ * Tests whether the given string can be encoded as a segment in alphanumeric mode.
+ */
+ public: static bool isAlphanumeric(const char *text);
+
+
+ /*
+ * Tests whether the given string can be encoded as a segment in numeric mode.
+ */
+ public: static bool isNumeric(const char *text);
+
+
+
+ /*---- Instance fields ----*/
+
+ /* The mode indicator for this segment. */
+ private: Mode mode;
+
+ /* The length of this segment's unencoded data, measured in characters. Always zero or positive. */
+ private: int numChars;
+
+ /* The data bits of this segment. */
+ private: std::vector<bool> data;
+
+
+ /*---- Constructors ----*/
+
+ /*
+ * Creates a new QR Code data segment with the given parameters and data.
+ */
+ public: QrSegment(Mode md, int numCh, const std::vector<bool> &dt);
+
+
+ /*
+ * Creates a new QR Code data segment with the given parameters and data.
+ */
+ public: QrSegment(Mode md, int numCh, std::vector<bool> &&dt);
+
+
+ /*---- Methods ----*/
+
+ public: Mode getMode() const;
+
+
+ public: int getNumChars() const;
+
+
+ public: const std::vector<bool> &getData() const;
+
+
+ // Package-private helper function.
+ public: static int getTotalBits(const std::vector<QrSegment> &segs, int version);
+
+
+ /*---- Private constant ----*/
+
+ /* The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string. */
+ private: static const char *ALPHANUMERIC_CHARSET;
+
+};
+
+}