From 12bb1ea5999b94ad857b959ae5b1a13fd3051068 Mon Sep 17 00:00:00 2001 From: Rohit Paul <113459757+RohitPaul12345@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:47:58 +0530 Subject: [PATCH] Update databr.js --- src/databr.js | 106 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/databr.js b/src/databr.js index f40257f2..233043d1 100644 --- a/src/databr.js +++ b/src/databr.js @@ -39,12 +39,12 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) this.getNextBits = function( numBits) { - var bits = 0; + let bits = 0; if (numBits < this.bitPointer + 1) { // next word fits into current data block - var mask = 0; - for (var i = 0; i < numBits; i++) + let mask = 0; + for (let i = 0; i < numBits; i++) { mask += (1 << i); } @@ -57,8 +57,8 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) else if (numBits < this.bitPointer + 1 + 8) { // next word crosses 2 data blocks - var mask1 = 0; - for (var i = 0; i < this.bitPointer + 1; i++) + let mask1 = 0; + for (let i = 0; i < this.bitPointer + 1; i++) { mask1 += (1 << i); } @@ -76,27 +76,27 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) else if (numBits < this.bitPointer + 1 + 16) { // next word crosses 3 data blocks - var mask1 = 0; // mask of first block - var mask3 = 0; // mask of 3rd block + let mask1 = 0; // mask of first block + let mask3 = 0; // mask of 3rd block //bitPointer + 1 : number of bits of the 1st block //8 : number of the 2nd block (note that use already 8bits because next word uses 3 data blocks) //numBits - (bitPointer + 1 + 8) : number of bits of the 3rd block - for (var i = 0; i < this.bitPointer + 1; i++) + for (let i = 0; i < this.bitPointer + 1; i++) { mask1 += (1 << i); } - var bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1)); + let bitsFirstBlock = (this.blocks[this.blockPointer] & mask1) << (numBits - (this.bitPointer + 1)); this.blockPointer++; - var bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8)); + let bitsSecondBlock = this.blocks[this.blockPointer] << (numBits - (this.bitPointer + 1 + 8)); this.blockPointer++; - for (var i = 0; i < numBits - (this.bitPointer + 1 + 8); i++) + for (let i = 0; i < numBits - (this.bitPointer + 1 + 8); i++) { mask3 += (1 << i); } mask3 <<= 8 - (numBits - (this.bitPointer + 1 + 8)); - var bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8))); + let bitsThirdBlock = (this.blocks[this.blockPointer] & mask3) >> (8 - (numBits - (this.bitPointer + 1 + 8))); bits = bitsFirstBlock + bitsSecondBlock + bitsThirdBlock; this.bitPointer = this.bitPointer - (numBits - 8) % 8; @@ -120,7 +120,7 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } this.getDataLength=function( modeIndicator) { - var index = 0; + let index = 0; while (true) { if ((modeIndicator >> index) == 1) @@ -132,17 +132,17 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } this.getRomanAndFigureString=function( dataLength) { - var length = dataLength; - var intData = 0; - var strData = ""; - var tableRomanAndFigure = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'); + let length = dataLength; + let intData = 0; + let strData = ""; + let tableRomanAndFigure = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'); do { if (length > 1) { intData = this.getNextBits(11); - var firstLetter = Math.floor(intData / 45); - var secondLetter = intData % 45; + let firstLetter = Math.floor(intData / 45); + let secondLetter = intData % 45; strData += tableRomanAndFigure[firstLetter]; strData += tableRomanAndFigure[secondLetter]; length -= 2; @@ -160,9 +160,9 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } this.getFigureString=function( dataLength) { - var length = dataLength; - var intData = 0; - var strData = ""; + let length = dataLength; + let intData = 0; + let strData = ""; do { if (length >= 3) @@ -194,9 +194,9 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } this.get8bitByteArray=function( dataLength) { - var length = dataLength; - var intData = 0; - var output = new Array(); + let length = dataLength; + let intData = 0; + let output = new Array(); do { @@ -209,17 +209,17 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) } this.getKanjiString=function( dataLength) { - var length = dataLength; - var intData = 0; - var unicodeString = ""; + let length = dataLength; + let intData = 0; + let unicodeString = ""; do { intData = this.getNextBits(13); - var lowerByte = intData % 0xC0; - var higherByte = intData / 0xC0; + let lowerByte = intData % 0xC0; + let higherByte = intData / 0xC0; - var tempWord = (higherByte << 8) + lowerByte; - var shiftjisWord = 0; + let tempWord = (higherByte << 8) + lowerByte; + let shiftjisWord = 0; if (tempWord + 0x8140 <= 0x9FFC) { // between 8140 - 9FFC on Shift_JIS character set @@ -246,19 +246,19 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) this.parseECIValue = function () { - var intData = 0; - var firstByte = this.getNextBits(8); + let intData = 0; + let firstByte = this.getNextBits(8); if ((firstByte & 0x80) == 0) { intData = firstByte & 0x7F; } if ((firstByte & 0xC0) == 0x80) { // two bytes - var secondByte = this.getNextBits(8); + let secondByte = this.getNextBits(8); intData = ((firstByte & 0x3F) << 8) | secondByte; } if ((firstByte & 0xE0) == 0xC0) { // three bytes - var secondThirdBytes = this.getNextBits(8);; + let secondThirdBytes = this.getNextBits(8);; intData = ((firstByte & 0x1F) << 16) | secondThirdBytes; } return intData; @@ -266,15 +266,15 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) this.__defineGetter__("DataByte", function() { - var output = new Array(); - var MODE_NUMBER = 1; - var MODE_ROMAN_AND_NUMBER = 2; - var MODE_8BIT_BYTE = 4; - var MODE_ECI = 7; - var MODE_KANJI = 8; + let output = new Array(); + let MODE_NUMBER = 1; + let MODE_ROMAN_AND_NUMBER = 2; + let MODE_8BIT_BYTE = 4; + let MODE_ECI = 7; + let MODE_KANJI = 8; do { - var mode = this.NextMode(); + let mode = this.NextMode(); //canvas.println("mode: " + mode); if (mode == 0) { @@ -290,41 +290,41 @@ function QRCodeDataBlockReader(blocks, version, numErrorCorrectionCode) if(mode == MODE_ECI) { - var temp_sbyteArray3 = this.parseECIValue(); + let temp_sbyteArray3 = this.parseECIValue(); //output.push(temp_sbyteArray3); } else { - var dataLength = this.getDataLength(mode); + let dataLength = this.getDataLength(mode); if (dataLength < 1) throw "Invalid data length: " + dataLength; switch (mode) { case MODE_NUMBER: - var temp_str = this.getFigureString(dataLength); - var ta = new Array(temp_str.length); - for(var j=0;j