diff --git a/cpp/BitBuffer.cpp b/cpp/BitBuffer.cpp index d8a8357..7f1441a 100644 --- a/cpp/BitBuffer.cpp +++ b/cpp/BitBuffer.cpp @@ -21,7 +21,6 @@ * Software. */ -#include #include "BitBuffer.hpp" diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index cd55f03..d9bbc9e 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -55,8 +55,7 @@ QrCode QrCode::encodeText(const char *text, const Ecc &ecl) { QrCode QrCode::encodeBinary(const vector &data, const Ecc &ecl) { - vector segs; - segs.push_back(QrSegment::makeBytes(data)); + vector segs{QrSegment::makeBytes(data)}; return encodeSegments(segs, ecl); } @@ -97,7 +96,7 @@ QrCode QrCode::encodeSegments(const vector &segs, const Ecc &ecl, } // Add terminator and pad up to a byte if applicable - bb.appendBits(0, std::min(static_cast(4), dataCapacityBits - bb.size())); + bb.appendBits(0, std::min(4, dataCapacityBits - bb.size())); bb.appendBits(0, (8 - bb.size() % 8) % 8); // Pad with alternate bytes until data capacity is reached @@ -323,14 +322,13 @@ vector QrCode::appendErrorCorrection(const vector &data) const vector > blocks; const ReedSolomonGenerator rs(blockEccLen); for (int i = 0, k = 0; i < numBlocks; i++) { - vector dat; - dat.insert(dat.begin(), data.begin() + k, data.begin() + (k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1))); + vector dat(data.cbegin() + k, data.cbegin() + (k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1))); k += dat.size(); const vector ecc(rs.getRemainder(dat)); if (i < numShortBlocks) dat.push_back(0); - dat.insert(dat.end(), ecc.begin(), ecc.end()); - blocks.push_back(dat); + 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 @@ -487,9 +485,9 @@ long QrCode::getPenaltyScore() const { // Balance of black and white modules int black = 0; - for (int y = 0; y < size; y++) { - for (int x = 0; x < size; x++) { - if (module(x, y)) + for (const vector &row : modules) { + for (bool color : row) { + if (color) black++; } } diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 93fe88c..a9a21df 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -110,8 +110,8 @@ class QrCode final { private: int mask; // Private grids of modules/pixels (conceptually immutable) - private: std::vector> modules; // The modules of this QR Code symbol (false = white, true = black) - private: std::vector> isFunction; // Indicates function modules that are not subjected to masking + private: std::vector > modules; // The modules of this QR Code symbol (false = white, true = black) + private: std::vector > isFunction; // Indicates function modules that are not subjected to masking diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index 7e1960b..e65c276 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -22,7 +22,6 @@ */ #include -#include #include #include "QrSegment.hpp"