Public function - see documentation comment in header file.
| 788 | |
| 789 | // Public function - see documentation comment in header file. |
| 790 | struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]) { |
| 791 | assert(digits != NULL); |
| 792 | struct qrcodegen_Segment result; |
| 793 | size_t len = c_strlen(digits); |
| 794 | result.mode = qrcodegen_Mode_NUMERIC; |
| 795 | int bitLen = calcSegmentBitLength(result.mode, len); |
| 796 | assert(bitLen != -1); |
| 797 | result.numChars = (int)len; |
| 798 | if (bitLen > 0) |
| 799 | memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0])); |
| 800 | result.bitLength = 0; |
| 801 | |
| 802 | unsigned int accumData = 0; |
| 803 | int accumCount = 0; |
| 804 | for (; *digits != '\0'; digits++) { |
| 805 | char c = *digits; |
| 806 | assert('0' <= c && c <= '9'); |
| 807 | accumData = accumData * 10 + (c - '0'); |
| 808 | accumCount++; |
| 809 | if (accumCount == 3) { |
| 810 | appendBitsToBuffer(accumData, 10, buf, &result.bitLength); |
| 811 | accumData = 0; |
| 812 | accumCount = 0; |
| 813 | } |
| 814 | } |
| 815 | if (accumCount > 0) // 1 or 2 digits remaining |
| 816 | appendBitsToBuffer(accumData, accumCount * 3 + 1, buf, &result.bitLength); |
| 817 | assert(result.bitLength == bitLen); |
| 818 | result.data = buf; |
| 819 | return result; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | // Public function - see documentation comment in header file. |
no test coverage detected