From 67c62461d380352500fc39557fd9f046b7fe1d18 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 14 Oct 2019 00:20:16 +0000 Subject: [PATCH] Renamed some method parameters to completely avoid variable shadowing, in C++ and Java versions. --- cpp/QrCode.cpp | 26 +++++++-------- cpp/QrCode.hpp | 6 ++-- .../main/java/io/nayuki/qrcodegen/QrCode.java | 32 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index a6e2568..503f39c 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -126,13 +126,13 @@ QrCode QrCode::encodeSegments(const vector &segs, Ecc ecl, } -QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) : +QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int msk) : // Initialize fields and check arguments version(ver), errorCorrectionLevel(ecl) { if (ver < MIN_VERSION || ver > MAX_VERSION) throw std::domain_error("Version value out of range"); - if (mask < -1 || mask > 7) + if (msk < -1 || msk > 7) throw std::domain_error("Mask value out of range"); size = ver * 4 + 17; size_t sz = static_cast(size); @@ -145,24 +145,24 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) drawCodewords(allCodewords); // Do masking - if (mask == -1) { // Automatically choose best mask + if (msk == -1) { // Automatically choose best mask long minPenalty = LONG_MAX; for (int i = 0; i < 8; i++) { applyMask(i); drawFormatBits(i); long penalty = getPenaltyScore(); if (penalty < minPenalty) { - mask = i; + msk = i; minPenalty = penalty; } applyMask(i); // Undoes the mask due to XOR } } - if (mask < 0 || mask > 7) + if (msk < 0 || msk > 7) throw std::logic_error("Assertion error"); - this->mask = mask; - applyMask(mask); // Apply the final choice of mask - drawFormatBits(mask); // Overwrite old format bits + this->mask = msk; + applyMask(msk); // Apply the final choice of mask + drawFormatBits(msk); // Overwrite old format bits isFunction.clear(); isFunction.shrink_to_fit(); @@ -251,9 +251,9 @@ void QrCode::drawFunctionPatterns() { } -void QrCode::drawFormatBits(int mask) { +void QrCode::drawFormatBits(int msk) { // Calculate error correction code and pack bits - int data = getFormatBits(errorCorrectionLevel) << 3 | mask; // errCorrLvl is uint2, mask is uint3 + int data = getFormatBits(errorCorrectionLevel) << 3 | msk; // errCorrLvl is uint2, msk is uint3 int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >> 9) * 0x537); @@ -402,14 +402,14 @@ void QrCode::drawCodewords(const vector &data) { } -void QrCode::applyMask(int mask) { - if (mask < 0 || mask > 7) +void QrCode::applyMask(int msk) { + if (msk < 0 || msk > 7) throw std::domain_error("Mask value out of range"); size_t sz = static_cast(size); for (size_t y = 0; y < sz; y++) { for (size_t x = 0; x < sz; x++) { bool invert; - switch (mask) { + switch (msk) { case 0: invert = (x + y) % 2 == 0; break; case 1: invert = y % 2 == 0; break; case 2: invert = x % 3 == 0; break; diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 8ad519f..6babfdf 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -147,7 +147,7 @@ class QrCode final { * This is a low-level API that most users should not use directly. * A mid-level API is the encodeSegments() function. */ - public: QrCode(int ver, Ecc ecl, const std::vector &dataCodewords, int mask); + public: QrCode(int ver, Ecc ecl, const std::vector &dataCodewords, int msk); @@ -201,7 +201,7 @@ class QrCode final { // 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); + private: void drawFormatBits(int msk); // Draws two copies of the version bits (with its own error correction code), @@ -245,7 +245,7 @@ class QrCode final { // before masking. Due to the arithmetic of XOR, calling applyMask() with // the same mask value a second time will undo the mask. A final well-formed // QR Code needs exactly one (not zero, two, etc.) mask applied. - private: void applyMask(int mask); + private: void applyMask(int msk); // Calculates and returns the penalty score based on state of this QR Code's current modules. diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java index 68c4f99..59608e8 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java @@ -241,16 +241,16 @@ public final class QrCode { * @param ver the version number to use, which must be in the range 1 to 40 (inclusive) * @param ecl the error correction level to use * @param dataCodewords the bytes representing segments to encode (without ECC) - * @param mask the mask pattern to use, which is either −1 for automatic choice or from 0 to 7 for fixed choice + * @param msk the mask pattern to use, which is either −1 for automatic choice or from 0 to 7 for fixed choice * @throws NullPointerException if the byte array or error correction level is {@code null} * @throws IllegalArgumentException if the version or mask value is out of range, * or if the data is the wrong length for the specified version and error correction level */ - public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) { + public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int msk) { // Check arguments and initialize fields if (ver < MIN_VERSION || ver > MAX_VERSION) throw new IllegalArgumentException("Version value out of range"); - if (mask < -1 || mask > 7) + if (msk < -1 || msk > 7) throw new IllegalArgumentException("Mask value out of range"); version = ver; size = ver * 4 + 17; @@ -263,7 +263,7 @@ public final class QrCode { drawFunctionPatterns(); byte[] allCodewords = addEccAndInterleave(dataCodewords); drawCodewords(allCodewords); - this.mask = handleConstructorMasking(mask); + this.mask = handleConstructorMasking(msk); isFunction = null; } @@ -382,9 +382,9 @@ public final class QrCode { // 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) { + private void drawFormatBits(int msk) { // Calculate error correction code and pack bits - int data = errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3 + int data = errorCorrectionLevel.formatBits << 3 | msk; // errCorrLvl is uint2, mask is uint3 int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); @@ -543,13 +543,13 @@ public final class QrCode { // before masking. Due to the arithmetic of XOR, calling applyMask() with // the same mask value a second time will undo the mask. A final well-formed // QR Code needs exactly one (not zero, two, etc.) mask applied. - private void applyMask(int mask) { - if (mask < 0 || mask > 7) + private void applyMask(int msk) { + if (msk < 0 || msk > 7) throw new IllegalArgumentException("Mask value out of range"); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { boolean invert; - switch (mask) { + switch (msk) { case 0: invert = (x + y) % 2 == 0; break; case 1: invert = y % 2 == 0; break; case 2: invert = x % 3 == 0; break; @@ -569,24 +569,24 @@ public final class QrCode { // A messy helper function for the constructor. 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) { - if (mask == -1) { // Automatically choose best mask + private int handleConstructorMasking(int msk) { + if (msk == -1) { // Automatically choose best mask int minPenalty = Integer.MAX_VALUE; for (int i = 0; i < 8; i++) { applyMask(i); drawFormatBits(i); int penalty = getPenaltyScore(); if (penalty < minPenalty) { - mask = i; + msk = i; minPenalty = penalty; } applyMask(i); // Undoes the mask due to XOR } } - assert 0 <= mask && mask <= 7; - applyMask(mask); // Apply the final choice of mask - drawFormatBits(mask); // Overwrite old format bits - return mask; // The caller shall assign this value to the final-declared field + assert 0 <= msk && msk <= 7; + applyMask(msk); // Apply the final choice of mask + drawFormatBits(msk); // Overwrite old format bits + return msk; // The caller shall assign this value to the final-declared field }