Renamed QrSegment.getBits() to getData() in {Java, JavaScript, TypeScript, Python} code, to match C++ and Rust.

pull/39/merge
Project Nayuki 6 years ago
parent b7922a8dce
commit 950955a4c5

@ -173,7 +173,7 @@ public final class QrSegment {
* Always zero or positive. Not the same as the data's bit length. */ * Always zero or positive. Not the same as the data's bit length. */
public final int numChars; public final int numChars;
/** The data bits of this segment. Not {@code null}. Accessed through {@link #getBits()}. */ /** The data bits of this segment. Not {@code null}. Accessed through {@link #getData()}. */
final BitBuffer data; final BitBuffer data;
@ -205,7 +205,7 @@ public final class QrSegment {
* Returns the data bits of this segment. * Returns the data bits of this segment.
* @return a new copy of the data bits (not {@code null}) * @return a new copy of the data bits (not {@code null})
*/ */
public BitBuffer getBits() { public BitBuffer getData() {
return data.clone(); // Make defensive copy return data.clone(); // Make defensive copy
} }

@ -50,7 +50,7 @@
* - Constructor QrSegment(QrSegment.Mode mode, int numChars, list<int> bitData) * - Constructor QrSegment(QrSegment.Mode mode, int numChars, list<int> bitData)
* - Field QrSegment.Mode mode * - Field QrSegment.Mode mode
* - Field int numChars * - Field int numChars
* - Method getBits() -> list<int> * - Method getData() -> list<int>
* - Constants RegExp NUMERIC_REGEX, ALPHANUMERIC_REGEX * - Constants RegExp NUMERIC_REGEX, ALPHANUMERIC_REGEX
* - Enum Mode: * - Enum Mode:
* - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI * - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI
@ -597,7 +597,7 @@ var qrcodegen = new function() {
segs.forEach(function(seg) { segs.forEach(function(seg) {
bb.appendBits(seg.mode.modeBits, 4); bb.appendBits(seg.mode.modeBits, 4);
bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version)); bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version));
seg.getBits().forEach(function(bit) { seg.getData().forEach(function(bit) {
bb.push(bit); bb.push(bit);
}); });
}); });
@ -738,6 +738,8 @@ var qrcodegen = new function() {
/*---- Constructor (low level) ----*/ /*---- Constructor (low level) ----*/
if (numChars < 0 || !(mode instanceof Mode)) if (numChars < 0 || !(mode instanceof Mode))
throw "Invalid argument"; throw "Invalid argument";
// The data bits of this segment. Accessed through getData().
bitData = bitData.slice(); // Make defensive copy bitData = bitData.slice(); // Make defensive copy
// The mode indicator of this segment. // The mode indicator of this segment.
@ -749,7 +751,7 @@ var qrcodegen = new function() {
Object.defineProperty(this, "numChars", {value:numChars}); Object.defineProperty(this, "numChars", {value:numChars});
// Returns a new copy of the data bits of this segment. // Returns a new copy of the data bits of this segment.
this.getBits = function() { this.getData = function() {
return bitData.slice(); // Make defensive copy return bitData.slice(); // Make defensive copy
}; };
}; };
@ -856,7 +858,7 @@ var qrcodegen = new function() {
var ccbits = seg.mode.numCharCountBits(version); var ccbits = seg.mode.numCharCountBits(version);
if (seg.numChars >= (1 << ccbits)) if (seg.numChars >= (1 << ccbits))
return Infinity; // The segment's length doesn't fit the field's bit width return Infinity; // The segment's length doesn't fit the field's bit width
result += 4 + ccbits + seg.getBits().length; result += 4 + ccbits + seg.getData().length;
} }
return result; return result;
}; };

@ -51,7 +51,7 @@ This module "qrcodegen", public members:
- Constructor QrSegment(QrSegment.Mode mode, int numch, list<int> bitdata) - Constructor QrSegment(QrSegment.Mode mode, int numch, list<int> bitdata)
- Method get_mode() -> QrSegment.Mode - Method get_mode() -> QrSegment.Mode
- Method get_num_chars() -> int - Method get_num_chars() -> int
- Method get_bits() -> list<int> - Method get_data() -> list<int>
- Constants regex NUMERIC_REGEX, ALPHANUMERIC_REGEX - Constants regex NUMERIC_REGEX, ALPHANUMERIC_REGEX
- Enum Mode: - Enum Mode:
- Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI
@ -733,7 +733,7 @@ class QrSegment(object):
# Accessed through get_num_chars(). # Accessed through get_num_chars().
self._numchars = numch self._numchars = numch
# The data bits of this segment. Accessed through get_bits(). # The data bits of this segment. Accessed through get_data().
self._bitdata = list(bitdata) # Make defensive copy self._bitdata = list(bitdata) # Make defensive copy
@ -747,7 +747,7 @@ class QrSegment(object):
"""Returns the character count field of this segment.""" """Returns the character count field of this segment."""
return self._numchars return self._numchars
def get_bits(self): def get_data(self):
"""Returns a new copy of the data bits of this segment.""" """Returns a new copy of the data bits of this segment."""
return list(self._bitdata) # Make defensive copy return list(self._bitdata) # Make defensive copy

@ -118,7 +118,7 @@ namespace qrcodegen {
for (let seg of segs) { for (let seg of segs) {
bb.appendBits(seg.mode.modeBits, 4); bb.appendBits(seg.mode.modeBits, 4);
bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version)); bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version));
for (let b of seg.getBits()) for (let b of seg.getData())
bb.push(b); bb.push(b);
} }
if (bb.length != dataUsedBits) if (bb.length != dataUsedBits)
@ -783,7 +783,7 @@ namespace qrcodegen {
// Always zero or positive. Not the same as the data's bit length. // Always zero or positive. Not the same as the data's bit length.
public readonly numChars: int, public readonly numChars: int,
// The data bits of this segment. Accessed through getBits(). // The data bits of this segment. Accessed through getData().
private readonly bitData: Array<bit>) { private readonly bitData: Array<bit>) {
if (numChars < 0) if (numChars < 0)
@ -795,7 +795,7 @@ namespace qrcodegen {
/*-- Methods --*/ /*-- Methods --*/
// Returns a new copy of the data bits of this segment. // Returns a new copy of the data bits of this segment.
public getBits(): Array<bit> { public getData(): Array<bit> {
return this.bitData.slice(); // Make defensive copy return this.bitData.slice(); // Make defensive copy
} }

Loading…
Cancel
Save