| 56 | |
| 57 | |
| 58 | qrcodegen::QrSegment qrcodegen::QrSegment::makeNumeric(const char *digits) { |
| 59 | BitBuffer bb; |
| 60 | int accumData = 0; |
| 61 | int accumCount = 0; |
| 62 | int charCount = 0; |
| 63 | for (; *digits != '\0'; digits++, charCount++) { |
| 64 | char c = *digits; |
| 65 | if (c < '0' || c > '9') |
| 66 | throw "String contains non-numeric characters"; |
| 67 | accumData = accumData * 10 + (c - '0'); |
| 68 | accumCount++; |
| 69 | if (accumCount == 3) { |
| 70 | bb.appendBits(accumData, 10); |
| 71 | accumData = 0; |
| 72 | accumCount = 0; |
| 73 | } |
| 74 | } |
| 75 | if (accumCount > 0) // 1 or 2 digits remaining |
| 76 | bb.appendBits(accumData, accumCount * 3 + 1); |
| 77 | return QrSegment(Mode::NUMERIC, charCount, bb.getBytes(), bb.getBitLength()); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | qrcodegen::QrSegment qrcodegen::QrSegment::makeAlphanumeric(const char *text) { |
nothing calls this directly
no test coverage detected