From 57312a0638b102a134edba38304e31a1d34ce025 Mon Sep 17 00:00:00 2001 From: Christoph Oberhofer Date: Tue, 23 May 2017 20:49:08 +0200 Subject: [PATCH] 195: Extracted common method to BarcodeReader; --- src/reader/barcode_reader.js | 29 +++++++++++++++++++++++++++++ src/reader/code_39_reader.js | 27 --------------------------- src/reader/code_93_reader.js | 29 +---------------------------- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/src/reader/barcode_reader.js b/src/reader/barcode_reader.js index 67e8de4..74005f9 100644 --- a/src/reader/barcode_reader.js +++ b/src/reader/barcode_reader.js @@ -1,3 +1,5 @@ +import ArrayHelper from '../common/array_helper'; + function BarcodeReader(config, supplements) { this._row = []; this.config = config || {}; @@ -195,6 +197,33 @@ BarcodeReader.prototype._fillCounters = function(offset, end, isWhite) { return counters; }; +BarcodeReader.prototype._toCounters = function(start, counter) { + var self = this, + numCounters = counter.length, + end = self._row.length, + isWhite = !self._row[start], + i, + counterPos = 0; + + ArrayHelper.init(counter, 0); + + for ( i = start; i < end; i++) { + if (self._row[i] ^ isWhite) { + counter[counterPos]++; + } else { + counterPos++; + if (counterPos === numCounters) { + break; + } else { + counter[counterPos] = 1; + isWhite = !isWhite; + } + } + } + + return counter; +}; + Object.defineProperty(BarcodeReader.prototype, "FORMAT", { value: 'unknown', writeable: false diff --git a/src/reader/code_39_reader.js b/src/reader/code_39_reader.js index 5b66b19..5981107 100644 --- a/src/reader/code_39_reader.js +++ b/src/reader/code_39_reader.js @@ -20,33 +20,6 @@ var properties = { Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties); Code39Reader.prototype.constructor = Code39Reader; -Code39Reader.prototype._toCounters = function(start, counter) { - var self = this, - numCounters = counter.length, - end = self._row.length, - isWhite = !self._row[start], - i, - counterPos = 0; - - ArrayHelper.init(counter, 0); - - for ( i = start; i < end; i++) { - if (self._row[i] ^ isWhite) { - counter[counterPos]++; - } else { - counterPos++; - if (counterPos === numCounters) { - break; - } else { - counter[counterPos] = 1; - isWhite = !isWhite; - } - } - } - - return counter; -}; - Code39Reader.prototype._decode = function() { var self = this, counters = [0, 0, 0, 0, 0, 0, 0, 0, 0], diff --git a/src/reader/code_93_reader.js b/src/reader/code_93_reader.js index 42f8646..33c55d9 100644 --- a/src/reader/code_93_reader.js +++ b/src/reader/code_93_reader.js @@ -24,33 +24,6 @@ var properties = { Code93Reader.prototype = Object.create(BarcodeReader.prototype, properties); Code93Reader.prototype.constructor = Code93Reader; -Code93Reader.prototype._toCounters = function(start, counter) { - var self = this, - numCounters = counter.length, - end = self._row.length, - isWhite = !self._row[start], - i, - counterPos = 0; - - ArrayHelper.init(counter, 0); - - for ( i = start; i < end; i++) { - if (self._row[i] ^ isWhite) { - counter[counterPos]++; - } else { - counterPos++; - if (counterPos === numCounters) { - break; - } else { - counter[counterPos] = 1; - isWhite = !isWhite; - } - } - } - - return counter; -}; - Code93Reader.prototype._decode = function() { var self = this, counters = [0, 0, 0, 0, 0, 0], @@ -235,7 +208,7 @@ Code93Reader.prototype._decodeExtended = function(charArray) { case 'c': if (nextChar >= 'A' && nextChar <= 'O') { decodedChar = String.fromCharCode(nextCharCode - 32); - } else if (nextChar == 'Z') { + } else if (nextChar === 'Z') { decodedChar = ':'; } else { return null;