MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / qrcodegen_encodeText

Function qrcodegen_encodeText

modules/data/qrcode/qrcodegen.c:129–163  ·  view source on GitHub ↗

Public function - see documentation comment in header file.

Source from the content-addressed store, hash-verified

127
128// Public function - see documentation comment in header file.
129bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],
130 enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) {
131
132 size_t textLen = c_strlen(text);
133 if (textLen == 0)
134 return qrcodegen_encodeSegmentsAdvanced(NULL, 0, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode);
135 size_t bufLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion);
136
137 struct qrcodegen_Segment seg;
138 if (qrcodegen_isNumeric(text)) {
139 if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, textLen) > bufLen)
140 goto fail;
141 seg = qrcodegen_makeNumeric(text, tempBuffer);
142 } else if (qrcodegen_isAlphanumeric(text)) {
143 if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, textLen) > bufLen)
144 goto fail;
145 seg = qrcodegen_makeAlphanumeric(text, tempBuffer);
146 } else {
147 if (textLen > bufLen)
148 goto fail;
149 for (size_t i = 0; i < textLen; i++)
150 tempBuffer[i] = (uint8_t)c_read8(&text[i]);
151 seg.mode = qrcodegen_Mode_BYTE;
152 seg.bitLength = calcSegmentBitLength(seg.mode, textLen);
153 if (seg.bitLength == -1)
154 goto fail;
155 seg.numChars = (int)textLen;
156 seg.data = tempBuffer;
157 }
158 return qrcodegen_encodeSegmentsAdvanced(&seg, 1, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode);
159
160fail:
161 qrcode[0] = 0; // Set size to invalid value for safety
162 return false;
163}
164
165
166// Public function - see documentation comment in header file.

Callers 1

xs_qrcodeFunction · 0.85

Calls 7

qrcodegen_isNumericFunction · 0.85
qrcodegen_makeNumericFunction · 0.85
qrcodegen_isAlphanumericFunction · 0.85
calcSegmentBitLengthFunction · 0.85

Tested by

no test coverage detected