From 859438d183c1519d29e46df42f37a6e643ad09c8 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Thu, 4 Oct 2018 19:40:43 +0000 Subject: [PATCH] Moved QrCode class's max/min version constants, tweaked associated comments and blank lines, in all languages except C. --- cpp/QrCode.hpp | 14 ++++++-------- java/io/nayuki/qrcodegen/QrCode.java | 13 +++++-------- javascript/qrcodegen.js | 15 ++++++--------- python/qrcodegen.py | 11 ++++------- rust/src/lib.rs | 4 +--- typescript/qrcodegen.ts | 5 +---- 6 files changed, 23 insertions(+), 39 deletions(-) diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 4639a22..d4115cf 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -88,13 +88,6 @@ class QrCode final { - /*---- Public constants ----*/ - - public: static constexpr int MIN_VERSION = 1; - public: static constexpr int MAX_VERSION = 40; - - - /*---- Instance fields ----*/ // Immutable scalar parameters @@ -252,7 +245,11 @@ class QrCode final { private: static bool getBit(long x, int i); - /*---- Private tables of constants ----*/ + /*---- Constants and tables ----*/ + + public: static constexpr int MIN_VERSION = 1; + public: static constexpr int MAX_VERSION = 40; + // For use in getPenaltyScore(), when evaluating which mask is best. private: static const int PENALTY_N1; @@ -260,6 +257,7 @@ class QrCode final { 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]; diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 7279f04..c694f13 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -167,13 +167,6 @@ public final class QrCode { - /*---- Public constants ----*/ - - public static final int MIN_VERSION = 1; - public static final int MAX_VERSION = 40; - - - /*---- Instance fields ----*/ // Public immutable scalar parameters @@ -704,7 +697,11 @@ public final class QrCode { } - /*---- Private tables of constants ----*/ + /*---- Constants and tables ----*/ + + public static final int MIN_VERSION = 1; + public static final int MAX_VERSION = 40; + // For use in getPenaltyScore(), when evaluating which mask is best. private static final int PENALTY_N1 = 3; diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index f1d2323..a78bc1a 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -599,14 +599,6 @@ var qrcodegen = new function() { }; - /*---- Public constants for QrCode ----*/ - - var MIN_VERSION = 1; - var MAX_VERSION = 40; - Object.defineProperty(this.QrCode, "MIN_VERSION", {value:MIN_VERSION}); - Object.defineProperty(this.QrCode, "MAX_VERSION", {value:MAX_VERSION}); - - /*---- Private static helper functions for QrCode ----*/ var QrCode = {}; // Private object to assign properties to. Not the same object as 'this.QrCode'. @@ -639,7 +631,12 @@ var qrcodegen = new function() { }; - /*---- Private tables of constants for QrCode ----*/ + /*---- Constants and tables for QrCode ----*/ + + var MIN_VERSION = 1; + var MAX_VERSION = 40; + Object.defineProperty(this.QrCode, "MIN_VERSION", {value:MIN_VERSION}); + Object.defineProperty(this.QrCode, "MAX_VERSION", {value:MAX_VERSION}); // For use in getPenaltyScore(), when evaluating which mask is best. QrCode.PENALTY_N1 = 3; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 8edd562..f0462f7 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -142,12 +142,6 @@ class QrCode(object): return QrCode(bb.get_bytes(), mask, version, ecl) - # ---- Public constants ---- - - MIN_VERSION = 1 - MAX_VERSION = 40 - - # ---- Constructor ---- def __init__(self, datacodewords, mask, version, errcorlvl): @@ -529,7 +523,10 @@ class QrCode(object): * QrCode._NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver] - # ---- Private tables of constants ---- + # ---- Constants and tables ---- + + MIN_VERSION = 1 + MAX_VERSION = 40 # For use in getPenaltyScore(), when evaluating which mask is best. _PENALTY_N1 = 3 diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 069b50d..a43958a 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -673,14 +673,12 @@ impl QrCode { } -/*---- Public constants ----*/ +/*---- Cconstants and tables ----*/ pub const QrCode_MIN_VERSION: Version = Version( 1); pub const QrCode_MAX_VERSION: Version = Version(40); -/*---- Private tables of constants ----*/ - // For use in get_penalty_score(), when evaluating which mask is best. const PENALTY_N1: i32 = 3; const PENALTY_N2: i32 = 3; diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index ab6d1ef..3c11da2 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -604,20 +604,17 @@ namespace qrcodegen { } - /*-- Constants --*/ + /*-- Constants and tables --*/ public static readonly MIN_VERSION: int = 1; public static readonly MAX_VERSION: int = 40; - // For use in getPenaltyScore(), when evaluating which mask is best. private static readonly PENALTY_N1: int = 3; private static readonly PENALTY_N2: int = 3; private static readonly PENALTY_N3: int = 40; private static readonly PENALTY_N4: int = 10; - /*-- Private tables of constants --*/ - private static readonly ECC_CODEWORDS_PER_BLOCK: Array> = [ // 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