Changed 2 members to public in JavaScript code, changed 1 member to explicitly private in Python code.

pull/4/head
Nayuki Minase 9 years ago
parent f63f890235
commit a4cccee0b3

@ -50,6 +50,7 @@
* - Field QrSegment.Mode mode * - Field QrSegment.Mode mode
* - Field int numChars * - Field int numChars
* - Method getBits() -> list<int> * - Method getBits() -> list<int>
* - Constants RegExp NUMERIC_REGEX, ALPHANUMERIC_REGEX
* - Enum Mode: * - Enum Mode:
* - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI * - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI
*/ */
@ -742,7 +743,7 @@ var qrcodegen = new function() {
* 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 (!this.NUMERIC_REGEX.test(digits))
throw "String contains non-numeric characters"; throw "String contains non-numeric characters";
var bb = new BitBuffer(); var bb = new BitBuffer();
var i; var i;
@ -760,7 +761,7 @@ var qrcodegen = new function() {
* 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. * 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
*/ */
this.QrSegment.makeAlphanumeric = function(text) { this.QrSegment.makeAlphanumeric = function(text) {
if (!QrSegment.ALPHANUMERIC_REGEX.test(text)) if (!this.ALPHANUMERIC_REGEX.test(text))
throw "String contains unencodable characters in alphanumeric mode"; throw "String contains unencodable characters in alphanumeric mode";
var bb = new BitBuffer(); var bb = new BitBuffer();
var i; var i;
@ -783,9 +784,9 @@ var qrcodegen = new function() {
// Select the most efficient segment encoding automatically // Select the most efficient segment encoding automatically
if (text == "") if (text == "")
return []; return [];
else if (QrSegment.NUMERIC_REGEX.test(text)) else if (this.NUMERIC_REGEX.test(text))
return [this.makeNumeric(text)]; return [this.makeNumeric(text)];
else if (QrSegment.ALPHANUMERIC_REGEX.test(text)) else if (this.ALPHANUMERIC_REGEX.test(text))
return [this.makeAlphanumeric(text)]; return [this.makeAlphanumeric(text)];
else else
return [this.makeBytes(toUtf8ByteArray(text))]; return [this.makeBytes(toUtf8ByteArray(text))];
@ -813,11 +814,11 @@ var qrcodegen = new function() {
var QrSegment = {}; // Private object to assign properties to. Not the same object as 'this.QrSegment'. var QrSegment = {}; // Private object to assign properties to. Not the same object as 'this.QrSegment'.
// Can test whether a string is encodable in numeric mode (such as by using QrSegment.makeNumeric()). // (Public) Can test whether a string is encodable in numeric mode (such as by using QrSegment.makeNumeric()).
QrSegment.NUMERIC_REGEX = /^[0-9]*$/; this.QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
// Can test whether a string is encodable in alphanumeric mode (such as by using QrSegment.makeAlphanumeric()). // (Public) Can test whether a string is encodable in alphanumeric mode (such as by using QrSegment.makeAlphanumeric()).
QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/; this.QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
// Maps shifted ASCII codes to alphanumeric mode character codes. // Maps shifted ASCII codes to alphanumeric mode character codes.
QrSegment.ALPHANUMERIC_ENCODING_TABLE = [ QrSegment.ALPHANUMERIC_ENCODING_TABLE = [

@ -637,11 +637,11 @@ class QrSegment(object):
raise ValueError("String contains unencodable characters in alphanumeric mode") raise ValueError("String contains unencodable characters in alphanumeric mode")
bb = _BitBuffer() bb = _BitBuffer()
for i in range(0, len(text) - 1, 2): # Process groups of 2 for i in range(0, len(text) - 1, 2): # Process groups of 2
temp = QrSegment.ALPHANUMERIC_ENCODING_TABLE[text[i]] * 45 temp = QrSegment._ALPHANUMERIC_ENCODING_TABLE[text[i]] * 45
temp += QrSegment.ALPHANUMERIC_ENCODING_TABLE[text[i + 1]] temp += QrSegment._ALPHANUMERIC_ENCODING_TABLE[text[i + 1]]
bb.append_bits(temp, 11) bb.append_bits(temp, 11)
if len(text) % 2 > 0: # 1 character remaining if len(text) % 2 > 0: # 1 character remaining
bb.append_bits(QrSegment.ALPHANUMERIC_ENCODING_TABLE[text[-1]], 6) bb.append_bits(QrSegment._ALPHANUMERIC_ENCODING_TABLE[text[-1]], 6)
return QrSegment(QrSegment.Mode.ALPHANUMERIC, len(text), bb.get_bits()) return QrSegment(QrSegment.Mode.ALPHANUMERIC, len(text), bb.get_bits())
@ -708,8 +708,8 @@ class QrSegment(object):
# Can test whether a string is encodable in alphanumeric mode (such as by using make_alphanumeric()) # Can test whether a string is encodable in alphanumeric mode (such as by using make_alphanumeric())
ALPHANUMERIC_REGEX = re.compile("[A-Z0-9 $%*+./:-]*$") ALPHANUMERIC_REGEX = re.compile("[A-Z0-9 $%*+./:-]*$")
# Dictionary of "0"->0, "A"->10, "$"->37, etc. # (Private) Dictionary of "0"->0, "A"->10, "$"->37, etc.
ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")} _ALPHANUMERIC_ENCODING_TABLE = {ch: i for (i, ch) in enumerate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")}
# ---- Public helper enumeration ---- # ---- Public helper enumeration ----

Loading…
Cancel
Save