Simplified C code to directly assign useful values to the segment mode enum.

pull/39/merge
Project Nayuki 6 years ago
parent be143456be
commit 30aed54c47

@ -912,16 +912,7 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
int bitLen = 0;
for (size_t i = 0; i < len; i++) {
const struct qrcodegen_Segment *seg = &segs[i];
unsigned int modeBits;
switch (seg->mode) {
case qrcodegen_Mode_NUMERIC : modeBits = 0x1; break;
case qrcodegen_Mode_ALPHANUMERIC: modeBits = 0x2; break;
case qrcodegen_Mode_BYTE : modeBits = 0x4; break;
case qrcodegen_Mode_KANJI : modeBits = 0x8; break;
case qrcodegen_Mode_ECI : modeBits = 0x7; break;
default: assert(false); return false;
}
appendBitsToBuffer(modeBits, 4, qrcode, &bitLen);
appendBitsToBuffer((int)seg->mode, 4, qrcode, &bitLen);
appendBitsToBuffer(seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen);
for (int j = 0; j < seg->bitLength; j++)
appendBitsToBuffer((seg->data[j >> 3] >> (7 - (j & 7))) & 1, 1, qrcode, &bitLen);

@ -69,11 +69,11 @@ enum qrcodegen_Mask {
* The mode field of a segment.
*/
enum qrcodegen_Mode {
qrcodegen_Mode_NUMERIC,
qrcodegen_Mode_ALPHANUMERIC,
qrcodegen_Mode_BYTE,
qrcodegen_Mode_KANJI,
qrcodegen_Mode_ECI,
qrcodegen_Mode_NUMERIC = 0x1,
qrcodegen_Mode_ALPHANUMERIC = 0x2,
qrcodegen_Mode_BYTE = 0x4,
qrcodegen_Mode_KANJI = 0x8,
qrcodegen_Mode_ECI = 0x7,
};

Loading…
Cancel
Save