* Get the type by string length * * @private * @param {String} sText * @param {Number} nCorrectLevel * @return {Number} type
(sText, nCorrectLevel)
| 467 | * @return {Number} type |
| 468 | */ |
| 469 | function _getTypeNumber(sText, nCorrectLevel) { |
| 470 | var nType = 1; |
| 471 | var length = _getUTF8Length(sText); |
| 472 | |
| 473 | for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) { |
| 474 | var nLimit = 0; |
| 475 | |
| 476 | switch (nCorrectLevel) { |
| 477 | case QRErrorCorrectLevel.L : |
| 478 | nLimit = QRCodeLimitLength[i][0]; |
| 479 | break; |
| 480 | case QRErrorCorrectLevel.M : |
| 481 | nLimit = QRCodeLimitLength[i][1]; |
| 482 | break; |
| 483 | case QRErrorCorrectLevel.Q : |
| 484 | nLimit = QRCodeLimitLength[i][2]; |
| 485 | break; |
| 486 | case QRErrorCorrectLevel.H : |
| 487 | nLimit = QRCodeLimitLength[i][3]; |
| 488 | break; |
| 489 | } |
| 490 | |
| 491 | if (length <= nLimit) { |
| 492 | break; |
| 493 | } else { |
| 494 | nType++; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (nType > QRCodeLimitLength.length) { |
| 499 | throw new Error("Too long data"); |
| 500 | } |
| 501 | |
| 502 | return nType; |
| 503 | } |
| 504 | |
| 505 | function _getUTF8Length(sText) { |
| 506 | var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a'); |
no test coverage detected