MCPcopy
hub / github.com/kciter/qart.js / qrAlphaNum

Function qrAlphaNum

src/qrcode.js:1445–1499  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

1443 // ---------------------------------------------------------------------
1444
1445 var qrAlphaNum = function (data) {
1446 var _mode = QRMode.MODE_ALPHA_NUM
1447 var _data = data
1448
1449 var _this = {}
1450
1451 _this.getMode = function () {
1452 return _mode
1453 }
1454
1455 _this.getLength = function (buffer) {
1456 return _data.length
1457 }
1458
1459 _this.write = function (buffer) {
1460 var s = _data
1461
1462 var i = 0
1463
1464 while (i + 1 < s.length) {
1465 buffer.put(
1466 getCode(s.charAt(i)) * 45 +
1467 getCode(s.charAt(i + 1)), 11)
1468 i += 2
1469 }
1470
1471 if (i < s.length) {
1472 buffer.put(getCode(s.charAt(i)), 6)
1473 }
1474 }
1475
1476 var getCode = function (c) {
1477 if (c >= '0' && c <= '9') {
1478 return c.charCodeAt(0) - '0'.charCodeAt(0)
1479 } else if (c >= 'A' && c <= 'Z') {
1480 return c.charCodeAt(0) - 'A'.charCodeAt(0) + 10
1481 } else {
1482 switch (c) {
1483 case ' ' : return 36
1484 case '$' : return 37
1485 case '%' : return 38
1486 case '*' : return 39
1487 case '+' : return 40
1488 case '-' : return 41
1489 case '.' : return 42
1490 case '/' : return 43
1491 case ':' : return 44
1492 default :
1493 throw 'illegal char :' + c
1494 }
1495 }
1496 }
1497
1498 return _this
1499 }
1500
1501 // ---------------------------------------------------------------------
1502 // qr8BitByte

Callers 1

qrcodeFunction · 0.85

Calls 1

getCodeFunction · 0.85

Tested by

no test coverage detected