Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update databr.js #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions src/databr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -246,35 +246,35 @@ 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;
}

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)
{
Expand All @@ -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<temp_str.length;j++)
let temp_str = this.getFigureString(dataLength);
let ta = new Array(temp_str.length);
for(let j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta);
break;

case MODE_ROMAN_AND_NUMBER:
var temp_str = this.getRomanAndFigureString(dataLength);
var ta = new Array(temp_str.length);
for(var j=0;j<temp_str.length;j++)
let temp_str = this.getRomanAndFigureString(dataLength);
let ta = new Array(temp_str.length);
for(let j=0;j<temp_str.length;j++)
ta[j]=temp_str.charCodeAt(j);
output.push(ta );
break;

case MODE_8BIT_BYTE:
var temp_sbyteArray3 = this.get8bitByteArray(dataLength);
let temp_sbyteArray3 = this.get8bitByteArray(dataLength);
output.push(temp_sbyteArray3);
break;

case MODE_KANJI:
var temp_str = this.getKanjiString(dataLength);
let temp_str = this.getKanjiString(dataLength);
output.push(temp_str);
break;
}
Expand Down