Tweaked section comments and blank lines for better uniformity across all language versions.
This commit is contained in:
parent
a8d8b6ddbe
commit
1df147943e
|
@ -225,7 +225,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Static helper functions ----*/
|
/*---- Private static helper functions ----*/
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Returns a set of positions of the alignment patterns in ascending order. These positions are
|
// 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);
|
static int getNumDataCodewords(int ver, const Ecc &ecl);
|
||||||
|
|
||||||
|
|
||||||
/*---- Tables of constants ----*/
|
/*---- Private tables of constants ----*/
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// For use in getPenaltyScore(), when evaluating which mask is best.
|
// For use in getPenaltyScore(), when evaluating which mask is best.
|
||||||
|
|
|
@ -47,8 +47,10 @@ class QrSegment final {
|
||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
class Mode final {
|
class Mode final {
|
||||||
// Constants.
|
|
||||||
|
/*-- Constants --*/
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const Mode NUMERIC;
|
static const Mode NUMERIC;
|
||||||
static const Mode ALPHANUMERIC;
|
static const Mode ALPHANUMERIC;
|
||||||
static const Mode BYTE;
|
static const Mode BYTE;
|
||||||
|
@ -65,23 +67,25 @@ public:
|
||||||
int numBitsCharCount[3];
|
int numBitsCharCount[3];
|
||||||
|
|
||||||
|
|
||||||
// Constructor.
|
/*-- Constructor --*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mode(int mode, int cc0, int cc1, int cc2);
|
Mode(int mode, int cc0, int cc1, int cc2);
|
||||||
|
|
||||||
|
|
||||||
/*-- Method --*/
|
/*-- Method --*/
|
||||||
public:
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the bit width of the segment character count field for this mode object at the given version number.
|
* 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;
|
int numCharCountBits(int ver) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---- Static factory functions ----*/
|
/*---- Public static factory functions ----*/
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -110,7 +114,7 @@ public:
|
||||||
static std::vector<QrSegment> makeSegments(const char *text);
|
static std::vector<QrSegment> makeSegments(const char *text);
|
||||||
|
|
||||||
|
|
||||||
/*---- Static helper functions ----*/
|
/*---- Public static helper functions ----*/
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -155,7 +159,7 @@ public:
|
||||||
static int getTotalBits(const std::vector<QrSegment> &segs, int version);
|
static int getTotalBits(const std::vector<QrSegment> &segs, int version);
|
||||||
|
|
||||||
|
|
||||||
/*---- Constant ----*/
|
/*---- Private constant ----*/
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static const int8_t ALPHANUMERIC_ENCODING_TABLE[59];
|
static const int8_t ALPHANUMERIC_ENCODING_TABLE[59];
|
||||||
|
|
|
@ -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
|
// 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).
|
// 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.
|
// For use in getPenaltyScore(), when evaluating which mask is best.
|
||||||
private static final int PENALTY_N1 = 3;
|
private static final int PENALTY_N1 = 3;
|
||||||
|
|
|
@ -230,7 +230,9 @@ public final class QrSegment {
|
||||||
* The mode field of a segment. Immutable. Provides methods to retrieve closely related values.
|
* The mode field of a segment. Immutable. Provides methods to retrieve closely related values.
|
||||||
*/
|
*/
|
||||||
public enum Mode {
|
public enum Mode {
|
||||||
// Constants.
|
|
||||||
|
/*-- Constants --*/
|
||||||
|
|
||||||
NUMERIC (0x1, 10, 12, 14),
|
NUMERIC (0x1, 10, 12, 14),
|
||||||
ALPHANUMERIC(0x2, 9, 11, 13),
|
ALPHANUMERIC(0x2, 9, 11, 13),
|
||||||
BYTE (0x4, 8, 16, 16),
|
BYTE (0x4, 8, 16, 16),
|
||||||
|
@ -245,7 +247,8 @@ public final class QrSegment {
|
||||||
private final int[] numBitsCharCount;
|
private final int[] numBitsCharCount;
|
||||||
|
|
||||||
|
|
||||||
// Constructor.
|
/*-- Constructor --*/
|
||||||
|
|
||||||
private Mode(int mode, int... ccbits) {
|
private Mode(int mode, int... ccbits) {
|
||||||
this.modeBits = mode;
|
this.modeBits = mode;
|
||||||
numBitsCharCount = ccbits;
|
numBitsCharCount = ccbits;
|
||||||
|
@ -266,6 +269,7 @@ public final class QrSegment {
|
||||||
else if (27 <= ver && ver <= 40) return numBitsCharCount[2];
|
else if (27 <= ver && ver <= 40) return numBitsCharCount[2];
|
||||||
else throw new IllegalArgumentException("Version number out of range");
|
else throw new IllegalArgumentException("Version number out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ var qrcodegen = new function() {
|
||||||
*/
|
*/
|
||||||
this.QrCode = function(initData, mask, version, errCorLvl) {
|
this.QrCode = function(initData, mask, version, errCorLvl) {
|
||||||
|
|
||||||
/*-- Constructor --*/
|
/*---- Constructor ----*/
|
||||||
|
|
||||||
// Handle simple scalar fields
|
// Handle simple scalar fields
|
||||||
if (mask < -1 || mask > 7)
|
if (mask < -1 || mask > 7)
|
||||||
|
@ -141,7 +141,8 @@ var qrcodegen = new function() {
|
||||||
drawFormatBits(mask); // Overwrite old format bits
|
drawFormatBits(mask); // Overwrite old format bits
|
||||||
applyMask(mask); // Apply the final choice of mask
|
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).
|
// This QR Code symbol's version number, which is always between 1 and 40 (inclusive).
|
||||||
Object.defineProperty(this, "version", {value:version});
|
Object.defineProperty(this, "version", {value:version});
|
||||||
|
@ -160,7 +161,7 @@ var qrcodegen = new function() {
|
||||||
Object.defineProperty(this, "mask", {value:mask});
|
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
|
// 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.
|
// 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
|
// 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.
|
// 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() {
|
function drawFunctionPatterns() {
|
||||||
// Draw the horizontal and vertical timing patterns
|
// Draw the horizontal and vertical timing patterns
|
||||||
|
@ -530,6 +531,7 @@ var qrcodegen = new function() {
|
||||||
return this.encodeSegments([seg], ecl);
|
return this.encodeSegments([seg], ecl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a QR Code symbol representing the specified data segments with the specified encoding parameters.
|
* 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.
|
* 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
|
var QrCode = {}; // Private object to assign properties to
|
||||||
|
|
||||||
|
|
||||||
// Returns a sequence of positions of the alignment patterns in ascending order. These positions are
|
// 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).
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// This stateless pure function could be implemented as a 40-entry lookup table.
|
||||||
|
@ -632,6 +636,7 @@ var qrcodegen = new function() {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
// 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.
|
// 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.
|
// 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.
|
// For use in getPenaltyScore(), when evaluating which mask is best.
|
||||||
QrCode.PENALTY_N1 = 3;
|
QrCode.PENALTY_N1 = 3;
|
||||||
|
@ -669,12 +674,14 @@ var qrcodegen = new function() {
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
// Private constructor for the enum.
|
/*---- Public helper enumeration ----*/
|
||||||
|
|
||||||
function Ecc(ord, fb) {
|
function Ecc(ord, fb) {
|
||||||
Object.defineProperty(this, "ordinal", {value:ord});
|
Object.defineProperty(this, "ordinal", {value:ord});
|
||||||
Object.defineProperty(this, "formatBits", {value:fb});
|
Object.defineProperty(this, "formatBits", {value:fb});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A public helper enumeration that represents the error correction level used in a QR Code symbol.
|
* 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).
|
* 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.
|
// Returns a segment representing the given binary data encoded in byte mode.
|
||||||
this.QrSegment.makeBytes = function(data) {
|
this.QrSegment.makeBytes = function(data) {
|
||||||
|
@ -726,6 +734,7 @@ var qrcodegen = new function() {
|
||||||
return new this(this.Mode.BYTE, data.length, bb.getBits());
|
return new this(this.Mode.BYTE, data.length, bb.getBits());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
||||||
this.QrSegment.makeNumeric = function(digits) {
|
this.QrSegment.makeNumeric = function(digits) {
|
||||||
if (!QrSegment.NUMERIC_REGEX.test(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());
|
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.
|
* 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.
|
* 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))];
|
return [this.makeBytes(toUtf8ByteArray(text))];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Package-private helper function.
|
// Package-private helper function.
|
||||||
this.QrSegment.getTotalBits = function(segs, version) {
|
this.QrSegment.getTotalBits = function(segs, version) {
|
||||||
if (version < 1 || version > 40)
|
if (version < 1 || version > 40)
|
||||||
|
@ -789,7 +800,8 @@ var qrcodegen = new function() {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-- Constants --*/
|
|
||||||
|
/*---- Constants for QrSegment ----*/
|
||||||
|
|
||||||
var QrSegment = {}; // Private object to assign properties to
|
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.
|
* A public helper enumeration that represents the mode field of a segment.
|
||||||
* Objects are immutable. Provides methods to retrieve closely related values.
|
* 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]),
|
KANJI : new Mode(0x8, [ 8, 10, 12]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Private constructor for the enum.
|
// Private constructor for the enum.
|
||||||
function Mode(mode, ccbits) {
|
function Mode(mode, ccbits) {
|
||||||
// An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object.
|
// 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
|
// Array of bits; each item is the integer 0 or 1
|
||||||
var bitData = [];
|
var bitData = [];
|
||||||
|
|
||||||
/*-- Methods --*/
|
|
||||||
|
|
||||||
// Returns the number of bits in the buffer, which is a non-negative value.
|
// Returns the number of bits in the buffer, which is a non-negative value.
|
||||||
this.bitLength = function() {
|
this.bitLength = function() {
|
||||||
return bitData.length;
|
return bitData.length;
|
||||||
|
|
|
@ -541,7 +541,7 @@ class QrCode(object):
|
||||||
return QrCode._get_num_raw_data_modules(ver) // 8 - QrCode._NUM_ERROR_CORRECTION_CODEWORDS[ecl.ordinal][ver]
|
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.
|
# For use in getPenaltyScore(), when evaluating which mask is best.
|
||||||
_PENALTY_N1 = 3
|
_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.
|
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."""
|
Any segment longer than this is meaningless for the purpose of generating QR Codes."""
|
||||||
|
|
||||||
# -- Public static factory functions --
|
# ---- Public static factory functions ----
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_bytes(data):
|
def make_bytes(data):
|
||||||
|
@ -665,7 +665,7 @@ class QrSegment(object):
|
||||||
return [QrSegment.make_bytes(text.encode("UTF-8"))]
|
return [QrSegment.make_bytes(text.encode("UTF-8"))]
|
||||||
|
|
||||||
|
|
||||||
# -- Constructor --
|
# ---- Constructor ----
|
||||||
|
|
||||||
def __init__(self, mode, numch, bitdata):
|
def __init__(self, mode, numch, bitdata):
|
||||||
if numch < 0 or not isinstance(mode, QrSegment.Mode):
|
if numch < 0 or not isinstance(mode, QrSegment.Mode):
|
||||||
|
@ -675,7 +675,7 @@ class QrSegment(object):
|
||||||
self._bitdata = list(bitdata) # Defensive copy
|
self._bitdata = list(bitdata) # Defensive copy
|
||||||
|
|
||||||
|
|
||||||
# -- Accessor methods --
|
# ---- Accessor methods ----
|
||||||
|
|
||||||
def get_mode(self):
|
def get_mode(self):
|
||||||
return self._mode
|
return self._mode
|
||||||
|
@ -702,7 +702,7 @@ class QrSegment(object):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# -- Constants --
|
# ---- Constants ----
|
||||||
|
|
||||||
# Can test whether a string is encodable in numeric mode (such as by using make_numeric())
|
# Can test whether a string is encodable in numeric mode (such as by using make_numeric())
|
||||||
NUMERIC_REGEX = re.compile("[0-9]*$")
|
NUMERIC_REGEX = re.compile("[0-9]*$")
|
||||||
|
@ -714,7 +714,7 @@ class QrSegment(object):
|
||||||
ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")}
|
ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")}
|
||||||
|
|
||||||
|
|
||||||
# -- Helper enumeration --
|
# ---- Public helper enumeration ----
|
||||||
|
|
||||||
class Mode(object):
|
class Mode(object):
|
||||||
"""The mode field of a segment. Immutable. Provides methods to retrieve closely related values."""
|
"""The mode field of a segment. Immutable. Provides methods to retrieve closely related values."""
|
||||||
|
|
Loading…
Reference in New Issue