Simplified C++ code by using for-each loop.

This commit is contained in:
Project Nayuki 2017-08-17 21:04:21 +00:00
parent f6e1276b08
commit 2c1991adad
2 changed files with 4 additions and 6 deletions

View File

@ -90,8 +90,7 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, const Ecc &ecl,
// Create the data bit string by concatenating all segments // Create the data bit string by concatenating all segments
int dataCapacityBits = getNumDataCodewords(version, *newEcl) * 8; int dataCapacityBits = getNumDataCodewords(version, *newEcl) * 8;
BitBuffer bb; BitBuffer bb;
for (size_t i = 0; i < segs.size(); i++) { for (const QrSegment &seg : segs) {
const QrSegment &seg(segs.at(i));
bb.appendBits(seg.mode.modeBits, 4); bb.appendBits(seg.mode.modeBits, 4);
bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version)); bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version));
bb.appendData(seg); bb.appendData(seg);
@ -596,8 +595,8 @@ QrCode::ReedSolomonGenerator::ReedSolomonGenerator(int degree) :
vector<uint8_t> QrCode::ReedSolomonGenerator::getRemainder(const vector<uint8_t> &data) const { vector<uint8_t> QrCode::ReedSolomonGenerator::getRemainder(const vector<uint8_t> &data) const {
// Compute the remainder by performing polynomial division // Compute the remainder by performing polynomial division
vector<uint8_t> result(coefficients.size()); vector<uint8_t> result(coefficients.size());
for (size_t i = 0; i < data.size(); i++) { for (uint8_t b : data) {
uint8_t factor = data.at(i) ^ result.at(0); uint8_t factor = b ^ result.at(0);
result.erase(result.begin()); result.erase(result.begin());
result.push_back(0); result.push_back(0);
for (size_t j = 0; j < result.size(); j++) for (size_t j = 0; j < result.size(); j++)

View File

@ -156,8 +156,7 @@ int QrSegment::getTotalBits(const vector<QrSegment> &segs, int version) {
if (version < 1 || version > 40) if (version < 1 || version > 40)
throw "Version number out of range"; throw "Version number out of range";
int result = 0; int result = 0;
for (std::size_t i = 0; i < segs.size(); i++) { for (const QrSegment &seg : segs) {
const QrSegment &seg(segs.at(i));
int ccbits = seg.mode.numCharCountBits(version); int ccbits = seg.mode.numCharCountBits(version);
// Fail if segment length value doesn't fit in the length field's bit-width // Fail if segment length value doesn't fit in the length field's bit-width
if (seg.numChars >= (1L << ccbits) || seg.bitLength > INT16_MAX) if (seg.numChars >= (1L << ccbits) || seg.bitLength > INT16_MAX)