Skip to content

Commit

Permalink
correct support of unicode texts davidshimjs#266 davidshimjs#236
Browse files Browse the repository at this point in the history
  • Loading branch information
se-ti committed Oct 6, 2022
1 parent 04f46c6 commit f13b042
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ var QRCode;
this.parsedData = [];

// Added to support UTF-8 Characters
var getCode = data.codePointAt || data.charCodeAt; // IE <= 11 doesn't has codePointAt
for (var i = 0, l = this.data.length; i < l; i++) {
var byteArray = [];
var code = this.data.charCodeAt(i);
var code = getCode.call(data, i);

if (code > 0x10000) {
if (code >= 0x10000) {
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[3] = 0x80 | (code & 0x3F);
} else if (code > 0x800) {
i++;
} else if (code >= 0x800) {
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[2] = 0x80 | (code & 0x3F);
} else if (code > 0x80) {
} else if (code >= 0x80) {
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
byteArray[1] = 0x80 | (code & 0x3F);
} else {
Expand Down

0 comments on commit f13b042

Please sign in to comment.