Tweaked comments and statement order in QrCode constructor, in most languages.
This commit is contained in:
parent
d060e97e03
commit
06d80aade3
|
@ -115,16 +115,14 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
|
|||
|
||||
|
||||
QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask) :
|
||||
// Initialize fields
|
||||
// Initialize fields and check arguments
|
||||
version(ver),
|
||||
size(MIN_VERSION <= ver && ver <= MAX_VERSION ? ver * 4 + 17 : -1), // Avoid signed overflow undefined behavior
|
||||
errorCorrectionLevel(ecl),
|
||||
modules (size, vector<bool>(size)), // Initially all white
|
||||
isFunction(size, vector<bool>(size)) {
|
||||
|
||||
// Check arguments
|
||||
if (ver < MIN_VERSION || ver > MAX_VERSION || mask < -1 || mask > 7)
|
||||
throw std::domain_error("Value out of range");
|
||||
size = ver * 4 + 17;
|
||||
|
||||
// Compute ECC, draw modules, do masking
|
||||
drawFunctionPatterns();
|
||||
|
|
|
@ -213,15 +213,13 @@ public final class QrCode {
|
|||
* 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) {
|
||||
// Check arguments
|
||||
errorCorrectionLevel = Objects.requireNonNull(ecl);
|
||||
Objects.requireNonNull(dataCodewords);
|
||||
// Check arguments and initialize fields
|
||||
if (ver < MIN_VERSION || ver > MAX_VERSION || mask < -1 || mask > 7)
|
||||
throw new IllegalArgumentException("Value out of range");
|
||||
|
||||
// Initialize fields
|
||||
version = ver;
|
||||
size = ver * 4 + 17;
|
||||
errorCorrectionLevel = Objects.requireNonNull(ecl);
|
||||
Objects.requireNonNull(dataCodewords);
|
||||
modules = new boolean[size][size]; // Initially all white
|
||||
isFunction = new boolean[size][size];
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ var qrcodegen = new function() {
|
|||
|
||||
/*---- Constructor (low level) ----*/
|
||||
|
||||
// Check arguments and handle simple scalar fields
|
||||
if (mask < -1 || mask > 7)
|
||||
throw "Mask value out of range";
|
||||
// Check scalar arguments
|
||||
if (version < MIN_VERSION || version > MAX_VERSION)
|
||||
throw "Version value out of range";
|
||||
if (mask < -1 || mask > 7)
|
||||
throw "Mask value out of range";
|
||||
var size = version * 4 + 17;
|
||||
|
||||
// Initialize both grids to be size*size arrays of Boolean false
|
||||
|
|
|
@ -151,21 +151,21 @@ class QrCode(object):
|
|||
and mask number. mask = -1 is for automatic choice, or 0 to 7 for fixed choice. This is a cumbersome low-level constructor
|
||||
that should not be invoked directly by the user. To go one level up, see the QrCode.encode_segments() function."""
|
||||
|
||||
# Check arguments and handle simple scalar fields
|
||||
if not (-1 <= mask <= 7):
|
||||
raise ValueError("Mask value out of range")
|
||||
# Check scalar arguments and set fields
|
||||
if not (QrCode.MIN_VERSION <= version <= QrCode.MAX_VERSION):
|
||||
raise ValueError("Version value out of range")
|
||||
if not (-1 <= mask <= 7):
|
||||
raise ValueError("Mask value out of range")
|
||||
if not isinstance(errcorlvl, QrCode.Ecc):
|
||||
raise TypeError("QrCode.Ecc expected")
|
||||
self._version = version
|
||||
self._errcorlvl = errcorlvl
|
||||
self._size = version * 4 + 17
|
||||
self._errcorlvl = errcorlvl
|
||||
|
||||
if len(datacodewords) != QrCode._get_num_data_codewords(version, errcorlvl):
|
||||
raise ValueError("Invalid array length")
|
||||
|
||||
# Initialize grids of modules
|
||||
# Initialize both grids to be size*size arrays of Boolean false
|
||||
# The modules of this QR Code symbol (False = white, True = black). Immutable after constructor finishes
|
||||
self._modules = [[False] * self._size for _ in range(self._size)] # Initially all white
|
||||
# Indicates function modules that are not subjected to masking. Discarded when constructor finishes
|
||||
|
|
|
@ -160,11 +160,11 @@ namespace qrcodegen {
|
|||
// (mask = -1), the resulting object will still have a mask value between 0 and 7.
|
||||
public readonly mask: int) {
|
||||
|
||||
// Check arguments and handle simple scalar fields
|
||||
if (mask < -1 || mask > 7)
|
||||
throw "Mask value out of range";
|
||||
// Check scalar arguments
|
||||
if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
|
||||
throw "Version value out of range";
|
||||
if (mask < -1 || mask > 7)
|
||||
throw "Mask value out of range";
|
||||
this.size = version * 4 + 17;
|
||||
|
||||
// Initialize both grids to be size*size arrays of Boolean false
|
||||
|
|
Loading…
Reference in New Issue