pull/18/merge
pashaie 11 years ago
commit fb764ed468

@ -472,12 +472,38 @@ var qrcode = function() {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
qrcode.stringToBytes = function(s) { qrcode.stringToBytes = function(s) {
var bytes = new Array(); // http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
for (var i = 0; i < s.length; i += 1) { function toUTF8Array(str) {
var c = s.charCodeAt(i); var utf8 = [];
bytes.push(c & 0xff); for (var i=0; i < str.length; i++) {
} var charcode = str.charCodeAt(i);
return bytes; if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
return toUTF8Array(s);
}; };
//--------------------------------------------------------------------- //---------------------------------------------------------------------

Loading…
Cancel
Save