From 1df147943ed63995c488934e7da6159ecef6d4f4 Mon Sep 17 00:00:00 2001 From: Nayuki Minase Date: Wed, 20 Apr 2016 20:19:57 +0000 Subject: [PATCH] Tweaked section comments and blank lines for better uniformity across all language versions. --- cpp/QrCode.hpp | 4 +-- cpp/QrSegment.hpp | 16 +++++++---- java/io/nayuki/qrcodegen/QrCode.java | 4 +-- java/io/nayuki/qrcodegen/QrSegment.java | 8 ++++-- javascript/qrcodegen.js | 37 +++++++++++++++++-------- python/qrcodegen.py | 12 ++++---- 6 files changed, 51 insertions(+), 30 deletions(-) diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 7302fd3..bcc822e 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -225,7 +225,7 @@ private: - /*---- Static helper functions ----*/ + /*---- Private static helper functions ----*/ private: // Returns a set of positions of the alignment patterns in ascending order. These positions are @@ -246,7 +246,7 @@ private: static int getNumDataCodewords(int ver, const Ecc &ecl); - /*---- Tables of constants ----*/ + /*---- Private tables of constants ----*/ private: // For use in getPenaltyScore(), when evaluating which mask is best. diff --git a/cpp/QrSegment.hpp b/cpp/QrSegment.hpp index 54682ee..79274c4 100644 --- a/cpp/QrSegment.hpp +++ b/cpp/QrSegment.hpp @@ -47,8 +47,10 @@ class QrSegment final { */ public: class Mode final { - // Constants. + + /*-- Constants --*/ public: + static const Mode NUMERIC; static const Mode ALPHANUMERIC; static const Mode BYTE; @@ -65,23 +67,25 @@ public: int numBitsCharCount[3]; - // Constructor. + /*-- Constructor --*/ + private: Mode(int mode, int cc0, int cc1, int cc2); /*-- Method --*/ - public: /* * Returns the bit width of the segment character count field for this mode object at the given version number. */ + public: int numCharCountBits(int ver) const; + }; - /*---- Static factory functions ----*/ + /*---- Public static factory functions ----*/ public: /* @@ -110,7 +114,7 @@ public: static std::vector makeSegments(const char *text); - /*---- Static helper functions ----*/ + /*---- Public static helper functions ----*/ public: /* @@ -155,7 +159,7 @@ public: static int getTotalBits(const std::vector &segs, int version); - /*---- Constant ----*/ + /*---- Private constant ----*/ private: static const int8_t ALPHANUMERIC_ENCODING_TABLE[59]; diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 663a4aa..fd62b68 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -652,7 +652,7 @@ public final class QrCode { - /*---- Static helper functions ----*/ + /*---- Private static helper functions ----*/ // Returns a set of positions of the alignment patterns in ascending order. These positions are // used on both the x and y axes. Each value in the resulting array is in the range [0, 177). @@ -715,7 +715,7 @@ public final class QrCode { } - /*---- Tables of constants ----*/ + /*---- Private tables of constants ----*/ // For use in getPenaltyScore(), when evaluating which mask is best. private static final int PENALTY_N1 = 3; diff --git a/java/io/nayuki/qrcodegen/QrSegment.java b/java/io/nayuki/qrcodegen/QrSegment.java index 1315a48..4d441da 100644 --- a/java/io/nayuki/qrcodegen/QrSegment.java +++ b/java/io/nayuki/qrcodegen/QrSegment.java @@ -230,7 +230,9 @@ public final class QrSegment { * The mode field of a segment. Immutable. Provides methods to retrieve closely related values. */ public enum Mode { - // Constants. + + /*-- Constants --*/ + NUMERIC (0x1, 10, 12, 14), ALPHANUMERIC(0x2, 9, 11, 13), BYTE (0x4, 8, 16, 16), @@ -245,7 +247,8 @@ public final class QrSegment { private final int[] numBitsCharCount; - // Constructor. + /*-- Constructor --*/ + private Mode(int mode, int... ccbits) { this.modeBits = mode; numBitsCharCount = ccbits; @@ -266,6 +269,7 @@ public final class QrSegment { else if (27 <= ver && ver <= 40) return numBitsCharCount[2]; else throw new IllegalArgumentException("Version number out of range"); } + } } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 5dbafd8..4e36ab7 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -79,7 +79,7 @@ var qrcodegen = new function() { */ this.QrCode = function(initData, mask, version, errCorLvl) { - /*-- Constructor --*/ + /*---- Constructor ----*/ // Handle simple scalar fields if (mask < -1 || mask > 7) @@ -141,7 +141,8 @@ var qrcodegen = new function() { drawFormatBits(mask); // Overwrite old format bits applyMask(mask); // Apply the final choice of mask - // Define read-only properties + + /*---- Read-only instance properties ----*/ // This QR Code symbol's version number, which is always between 1 and 40 (inclusive). Object.defineProperty(this, "version", {value:version}); @@ -160,7 +161,7 @@ var qrcodegen = new function() { Object.defineProperty(this, "mask", {value:mask}); - /*-- Accessor methods --*/ + /*---- Accessor methods ----*/ // Returns the color of the module (pixel) at the given coordinates, which is either 0 for white or 1 for black. The top // left corner has the coordinates (x=0, y=0). If the given coordinates are out of bounds, then 0 (white) is returned. @@ -181,7 +182,7 @@ var qrcodegen = new function() { }; - /*-- Public instance methods --*/ + /*---- Public instance methods ----*/ // Based on the given number of border modules to add as padding, this returns a // string whose contents represents an SVG XML file that depicts this QR Code symbol. @@ -211,7 +212,7 @@ var qrcodegen = new function() { }; - /*-- Private helper methods for constructor: Drawing function modules --*/ + /*---- Private helper methods for constructor: Drawing function modules ----*/ function drawFunctionPatterns() { // Draw the horizontal and vertical timing patterns @@ -530,6 +531,7 @@ var qrcodegen = new function() { return this.encodeSegments([seg], ecl); }; + /* * Returns a QR Code symbol representing the specified data segments with the specified encoding parameters. * The smallest possible QR Code version within the specified range is automatically chosen for the output. @@ -586,10 +588,11 @@ var qrcodegen = new function() { }; - /*---- Private static helper functions ----*/ + /*---- Private static helper functions QrCode ----*/ var QrCode = {}; // Private object to assign properties to + // Returns a sequence of positions of the alignment patterns in ascending order. These positions are // used on both the x and y axes. Each value in the resulting sequence is in the range [0, 177). // This stateless pure function could be implemented as table of 40 variable-length lists of integers. @@ -616,6 +619,7 @@ var qrcodegen = new function() { } }; + // Returns the number of raw data modules (bits) available at the given version number. // These data modules are used for both user data codewords and error correction codewords. // This stateless pure function could be implemented as a 40-entry lookup table. @@ -632,6 +636,7 @@ var qrcodegen = new function() { return result; }; + // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any // QR Code of the given version number and error correction level, with remainder bits discarded. // This stateless pure function could be implemented as a (40*4)-cell lookup table. @@ -642,7 +647,7 @@ var qrcodegen = new function() { }; - /*---- Tables of constants ----*/ + /*---- Private tables of constants for QrCode ----*/ // For use in getPenaltyScore(), when evaluating which mask is best. QrCode.PENALTY_N1 = 3; @@ -669,12 +674,14 @@ var qrcodegen = new function() { ]; - // Private constructor for the enum. + /*---- Public helper enumeration ----*/ + function Ecc(ord, fb) { Object.defineProperty(this, "ordinal", {value:ord}); Object.defineProperty(this, "formatBits", {value:fb}); } + /* * A public helper enumeration that represents the error correction level used in a QR Code symbol. * The fields 'ordinal' and 'formatBits' are in the range 0 to 3 (unsigned 2-bit integer). @@ -715,7 +722,8 @@ var qrcodegen = new function() { }; }; - /*-- Public static factory functions --*/ + + /*---- Public static factory functions for QrSegment ----*/ // Returns a segment representing the given binary data encoded in byte mode. this.QrSegment.makeBytes = function(data) { @@ -726,6 +734,7 @@ var qrcodegen = new function() { return new this(this.Mode.BYTE, data.length, bb.getBits()); }; + // Returns a segment representing the given string of decimal digits encoded in numeric mode. this.QrSegment.makeNumeric = function(digits) { if (!QrSegment.NUMERIC_REGEX.test(digits)) @@ -757,6 +766,7 @@ var qrcodegen = new function() { return new this(this.Mode.ALPHANUMERIC, text.length, bb.getBits()); }; + /* * Returns a new mutable list of zero or more segments to represent the given Unicode text string. * The result may use various segment modes and switch modes to optimize the length of the bit stream. @@ -773,6 +783,7 @@ var qrcodegen = new function() { return [this.makeBytes(toUtf8ByteArray(text))]; }; + // Package-private helper function. this.QrSegment.getTotalBits = function(segs, version) { if (version < 1 || version > 40) @@ -789,7 +800,8 @@ var qrcodegen = new function() { return result; }; - /*-- Constants --*/ + + /*---- Constants for QrSegment ----*/ var QrSegment = {}; // Private object to assign properties to @@ -807,6 +819,8 @@ var qrcodegen = new function() { ]; + /*---- Public helper enumeration ----*/ + /* * A public helper enumeration that represents the mode field of a segment. * Objects are immutable. Provides methods to retrieve closely related values. @@ -818,6 +832,7 @@ var qrcodegen = new function() { KANJI : new Mode(0x8, [ 8, 10, 12]), }; + // Private constructor for the enum. function Mode(mode, ccbits) { // An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object. @@ -929,8 +944,6 @@ var qrcodegen = new function() { // Array of bits; each item is the integer 0 or 1 var bitData = []; - /*-- Methods --*/ - // Returns the number of bits in the buffer, which is a non-negative value. this.bitLength = function() { return bitData.length; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 9797d81..284f522 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -541,7 +541,7 @@ class QrCode(object): return QrCode._get_num_raw_data_modules(ver) // 8 - QrCode._NUM_ERROR_CORRECTION_CODEWORDS[ecl.ordinal][ver] - # ---- Tables of constants ---- + # ---- Private tables of constants ---- # For use in getPenaltyScore(), when evaluating which mask is best. _PENALTY_N1 = 3 @@ -604,7 +604,7 @@ class QrSegment(object): Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. Any segment longer than this is meaningless for the purpose of generating QR Codes.""" - # -- Public static factory functions -- + # ---- Public static factory functions ---- @staticmethod def make_bytes(data): @@ -665,7 +665,7 @@ class QrSegment(object): return [QrSegment.make_bytes(text.encode("UTF-8"))] - # -- Constructor -- + # ---- Constructor ---- def __init__(self, mode, numch, bitdata): if numch < 0 or not isinstance(mode, QrSegment.Mode): @@ -675,7 +675,7 @@ class QrSegment(object): self._bitdata = list(bitdata) # Defensive copy - # -- Accessor methods -- + # ---- Accessor methods ---- def get_mode(self): return self._mode @@ -702,7 +702,7 @@ class QrSegment(object): return result - # -- Constants -- + # ---- Constants ---- # Can test whether a string is encodable in numeric mode (such as by using make_numeric()) NUMERIC_REGEX = re.compile("[0-9]*$") @@ -714,7 +714,7 @@ class QrSegment(object): ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")} - # -- Helper enumeration -- + # ---- Public helper enumeration ---- class Mode(object): """The mode field of a segment. Immutable. Provides methods to retrieve closely related values."""