From 0ee6c41c9c1a0d0a1d11b1af1f906ae9d769f7be Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 26 Aug 2018 01:33:06 +0000 Subject: [PATCH] Renamed QrCode.appendErrorCorrection() to addEccAndInterleave() in all language versions. --- c/qrcodegen-test.c | 12 ++++++------ c/qrcodegen.c | 6 +++--- cpp/QrCode.cpp | 4 ++-- cpp/QrCode.hpp | 2 +- java/io/nayuki/qrcodegen/QrCode.java | 4 ++-- javascript/qrcodegen.js | 4 ++-- python/qrcodegen.py | 4 ++-- rust/src/lib.rs | 4 ++-- typescript/qrcodegen.ts | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 4f9c5c0..0674587 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -52,7 +52,7 @@ static int numTestCases = 0; extern const int8_t ECC_CODEWORDS_PER_BLOCK[4][41]; extern const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41]; void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen); -void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); +void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); int getNumRawDataModules(int version); void calcReedSolomonGenerator(int degree, uint8_t result[]); @@ -111,7 +111,7 @@ static void testAppendBitsToBuffer(void) { // Ported from the Java version of the code. -static uint8_t *appendErrorCorrectionReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) { +static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) { // Calculate parameter numbers int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; int blockEccLen = ECC_CODEWORDS_PER_BLOCK[(int)ecl][version]; @@ -151,20 +151,20 @@ static uint8_t *appendErrorCorrectionReference(const uint8_t *data, int version, } -static void testAppendErrorCorrection(void) { +static void testAddEccAndInterleave(void) { for (int version = 1; version <= 40; version++) { for (int ecl = 0; ecl < 4; ecl++) { int dataLen = getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl); uint8_t *pureData = MALLOC(dataLen, uint8_t); for (int i = 0; i < dataLen; i++) pureData[i] = rand() % 256; - uint8_t *expectOutput = appendErrorCorrectionReference(pureData, version, (enum qrcodegen_Ecc)ecl); + uint8_t *expectOutput = addEccAndInterleaveReference(pureData, version, (enum qrcodegen_Ecc)ecl); int dataAndEccLen = getNumRawDataModules(version) / 8; uint8_t *paddedData = MALLOC(dataAndEccLen, uint8_t); memcpy(paddedData, pureData, dataLen * sizeof(uint8_t)); uint8_t *actualOutput = MALLOC(dataAndEccLen, uint8_t); - appendErrorCorrection(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput); + addEccAndInterleave(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput); assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0); free(pureData); @@ -1057,7 +1057,7 @@ static void testGetTotalBits(void) { int main(void) { srand(time(NULL)); testAppendBitsToBuffer(); - testAppendErrorCorrection(); + testAddEccAndInterleave(); testGetNumDataCodewords(); testGetNumRawDataModules(); testCalcReedSolomonGenerator(); diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 30f0bfc..b670ea1 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -60,7 +60,7 @@ testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen); -testable void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); +testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); testable int getNumRawDataModules(int version); @@ -195,7 +195,7 @@ testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[] // from the blocks and stores them in the result array. data[0 : rawCodewords - totalEcc] contains // the input data. data[rawCodewords - totalEcc : rawCodewords] is used as a temporary work area // and will be clobbered by this function. The final answer is stored in result[0 : rawCodewords]. -testable void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) { +testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) { // Calculate parameter numbers assert(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; @@ -948,7 +948,7 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz assert(bitLen % 8 == 0); // Draw function and data codeword modules - appendErrorCorrection(qrcode, version, ecl, tempBuffer); + addEccAndInterleave(qrcode, version, ecl, tempBuffer); initializeFunctionModules(version, qrcode); drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode); drawWhiteFunctionModules(qrcode, version); diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 09f93c0..58c234a 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -124,7 +124,7 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) // Draw function patterns, draw all codewords, do masking drawFunctionPatterns(); - const vector allCodewords = appendErrorCorrection(dataCodewords); + const vector allCodewords = addEccAndInterleave(dataCodewords); drawCodewords(allCodewords); this->mask = handleConstructorMasking(mask); } @@ -298,7 +298,7 @@ bool QrCode::module(int x, int y) const { } -vector QrCode::appendErrorCorrection(const vector &data) const { +vector QrCode::addEccAndInterleave(const vector &data) const { if (data.size() != static_cast(getNumDataCodewords(version, errorCorrectionLevel))) throw std::invalid_argument("Invalid argument"); diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 33edc93..f637513 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -201,7 +201,7 @@ class QrCode final { // 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 appendErrorCorrection(const std::vector &data) const; + private: std::vector addEccAndInterleave(const std::vector &data) const; // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 985c930..fbe16b7 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -226,7 +226,7 @@ public final class QrCode { // Draw function patterns, draw all codewords, do masking drawFunctionPatterns(); - byte[] allCodewords = appendErrorCorrection(dataCodewords); + byte[] allCodewords = addEccAndInterleave(dataCodewords); drawCodewords(allCodewords); this.mask = handleConstructorMasking(mask); } @@ -437,7 +437,7 @@ public final class QrCode { // 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 byte[] appendErrorCorrection(byte[] data) { + private byte[] addEccAndInterleave(byte[] data) { if (data.length != getNumDataCodewords(version, errorCorrectionLevel)) throw new IllegalArgumentException(); diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index f0fa2b5..3bf9f40 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -92,7 +92,7 @@ var qrcodegen = new function() { // Handle grid fields, draw function patterns, draw all codewords drawFunctionPatterns(); - var allCodewords = appendErrorCorrection(datacodewords); + var allCodewords = addEccAndInterleave(datacodewords); drawCodewords(allCodewords); // Handle masking @@ -310,7 +310,7 @@ var qrcodegen = new function() { // 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. - function appendErrorCorrection(data) { + function addEccAndInterleave(data) { if (data.length != QrCode.getNumDataCodewords(version, errCorLvl)) throw "Invalid argument"; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 833807e..58b8ab3 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -169,7 +169,7 @@ class QrCode(object): self._isfunction = [[False] * self._size for _ in range(self._size)] # Indicates function modules that are not subjected to masking # Draw function patterns, draw all codewords self._draw_function_patterns() - allcodewords = self._append_error_correction(datacodewords) + allcodewords = self._add_ecc_and_interleave(datacodewords) self._draw_codewords(allcodewords) # Handle masking @@ -345,7 +345,7 @@ class QrCode(object): # ---- Private helper methods for constructor: Codewords and masking ---- - def _append_error_correction(self, data): + def _add_ecc_and_interleave(self, data): """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.""" version = self._version diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7d9cdd8..149fbb8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -182,7 +182,7 @@ impl QrCode { // Draw function patterns, draw all codewords, do masking result.draw_function_patterns(); - let allcodewords: Vec = result.append_error_correction(datacodewords); + let allcodewords: Vec = result.add_ecc_and_interleave(datacodewords); result.draw_codewords(&allcodewords); result.handle_constructor_masking(mask); result @@ -403,7 +403,7 @@ impl QrCode { // 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. - fn append_error_correction(&self, data: &[u8]) -> Vec { + fn add_ecc_and_interleave(&self, data: &[u8]) -> Vec { let ver = self.version; let ecl = self.errorcorrectionlevel; assert_eq!(data.len(), QrCode::get_num_data_codewords(ver, ecl), "Illegal argument"); diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 1e140bb..f82adc6 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -170,7 +170,7 @@ namespace qrcodegen { // Handle grid fields, draw function patterns, draw all codewords this.drawFunctionPatterns(); - let allCodewords: Array = this.appendErrorCorrection(datacodewords); + let allCodewords: Array = this.addEccAndInterleave(datacodewords); this.drawCodewords(allCodewords); // Handle masking @@ -374,7 +374,7 @@ namespace qrcodegen { // 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 appendErrorCorrection(data: Array): Array { + private addEccAndInterleave(data: Array): Array { const ver: int = this.version; const ecl: QrCode_Ecc = this.errorCorrectionLevel; if (data.length != QrCode.getNumDataCodewords(ver, ecl))