Public function - see documentation comment in header file.
| 822 | |
| 823 | // Public function - see documentation comment in header file. |
| 824 | struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]) { |
| 825 | assert(text != NULL); |
| 826 | struct qrcodegen_Segment result; |
| 827 | size_t len = c_strlen(text); |
| 828 | result.mode = qrcodegen_Mode_ALPHANUMERIC; |
| 829 | int bitLen = calcSegmentBitLength(result.mode, len); |
| 830 | assert(bitLen != -1); |
| 831 | result.numChars = (int)len; |
| 832 | if (bitLen > 0) |
| 833 | memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0])); |
| 834 | result.bitLength = 0; |
| 835 | |
| 836 | unsigned int accumData = 0; |
| 837 | int accumCount = 0; |
| 838 | for (; c_read8(text) != '\0'; text++) { |
| 839 | const char *temp = c_strchr(ALPHANUMERIC_CHARSET, c_read8(text)); |
| 840 | assert(temp != NULL); |
| 841 | accumData = accumData * 45 + (temp - ALPHANUMERIC_CHARSET); |
| 842 | accumCount++; |
| 843 | if (accumCount == 2) { |
| 844 | appendBitsToBuffer(accumData, 11, buf, &result.bitLength); |
| 845 | accumData = 0; |
| 846 | accumCount = 0; |
| 847 | } |
| 848 | } |
| 849 | if (accumCount > 0) // 1 character remaining |
| 850 | appendBitsToBuffer(accumData, 6, buf, &result.bitLength); |
| 851 | assert(result.bitLength == bitLen); |
| 852 | result.data = buf; |
| 853 | return result; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | // Public function - see documentation comment in header file. |
no test coverage detected