From 30aed54c47cbe9eda1105857042422128d26ddcf Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 17 Sep 2018 03:31:00 +0000 Subject: [PATCH] Simplified C code to directly assign useful values to the segment mode enum. --- c/qrcodegen.c | 11 +---------- c/qrcodegen.h | 10 +++++----- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 2d1240d..59ba12a 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -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); diff --git a/c/qrcodegen.h b/c/qrcodegen.h index 852b955..4479f1f 100644 --- a/c/qrcodegen.h +++ b/c/qrcodegen.h @@ -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, };