1690 | function processInput (input, code) { |
1691 | var data, dataArr, i, c, len; |
1692 | |
1693 | switch (typeof input) { |
1694 | case 'string': |
1695 | data = input; |
1696 | break; |
1697 | case 'number': |
1698 | data = input.toString(); |
1699 | break; |
1700 | case 'object': |
1701 | if (input.constructor === window[___JSQR___].prototype.Input) { |
1702 | data = input.toString(); |
1703 | } else if ((Array.isArray || function(o) { return Object.prototype.toString.call(o) === '[object Array]'; })(input)) { |
1704 | return input; |
1705 | } else { |
1706 | data = (new window[___JSQR___].prototype.Input(input.dataType, input.data)).toString(); |
1707 | } |
1708 | break; |
1709 | default: |
1710 | throw new TypeError('Unsupported input parameter'); |
1711 | } |
1712 | |
1713 | dataArr = (code.encodeMode === code.ENCODE_MODE.UTF8_SIGNATURE ? [0xef, 0xbb , 0xbf] : []); |
1714 | |
1715 | if (code.encodeMode === code.ENCODE_MODE.UTF8_SIGNATURE || code.encodeMode === code.ENCODE_MODE.UTF8) { |
1716 | |
1717 | for (i = 0, len = data.length; i < len; i++) { |
1718 | c = data.charCodeAt(i); |
1719 | if (c < 128) { |
1720 | dataArr.push(c); |
1721 | } else if((c > 127) && (c < 2048)) { |
1722 | dataArr.push((c >> 6) | 192, (c & 63) | 128); |
1723 | } else { |
1724 | dataArr.push((c >> 12) | 224, ((c >> 6) & 63) | 128, (c & 63) | 128); |
1725 | } |
1726 | } |
1727 | } else { |
1728 | for (i = 0, len = data.length; i < len; i++) { |
1729 | dataArr.push(data.charCodeAt(i)); |
1730 | } |
1731 | } |
1732 | |
1733 | return dataArr; |
1734 | } |