summaryrefslogtreecommitdiff
path: root/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-01-12 23:07:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-12 23:07:54 +0000
commite11ef0ce9f3b5fc094a2f082972dfaf9a6c375aa (patch)
treee5352afdc9c62897e04603f0db9a0fe51afe87af /fxbarcode/oned/BC_OnedCodaBarWriter.cpp
parent53c4ba4011ab59ecc8406e144df8aaaa1169801b (diff)
downloadpdfium-e11ef0ce9f3b5fc094a2f082972dfaf9a6c375aa.tar.xz
Fix some nits in fxbarcode.chromium/3322chromium/3321chromium/3320
This is a follow-up to comments from https://pdfium-review.googlesource.com/c/pdfium/+/22870 Change-Id: Ide35ea5b27ea12d480d979241801c7676b94fe74 Reviewed-on: https://pdfium-review.googlesource.com/22932 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/oned/BC_OnedCodaBarWriter.cpp')
-rw-r--r--fxbarcode/oned/BC_OnedCodaBarWriter.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index 3c3ea4afe8..42990f7f3a 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -30,16 +30,21 @@
namespace {
-const char kOnedCodaAlphabet[] = "0123456789-$:/.+ABCDTN";
-
-const int32_t kOnedCodaCharacterEncoding[22] = {
- 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024,
- 0x030, 0x048, 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015,
- 0x01A, 0x029, 0x00B, 0x00E, 0x01A, 0x029};
-
-const char START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E',
- 'a', 'b', 'c', 'd', 't', 'n', 'e'};
-const char CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+const char kOnedCodaAlphabet[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '-', '$', ':', '/', '.', '+',
+ 'A', 'B', 'C', 'D', 'T', 'N'};
+
+const int8_t kOnedCodaCharacterEncoding[] = {
+ 0x03, 0x06, 0x09, 0x60, 0x12, 0x42, 0x21, 0x24, 0x30, 0x48, 0x0c,
+ 0x18, 0x45, 0x51, 0x54, 0x15, 0x1A, 0x29, 0x0B, 0x0E, 0x1A, 0x29};
+static_assert(FX_ArraySize(kOnedCodaCharacterEncoding) == 22, "Wrong size");
+static_assert(FX_ArraySize(kOnedCodaCharacterEncoding) ==
+ FX_ArraySize(kOnedCodaAlphabet),
+ "Wrong size");
+
+const char kStartEndChars[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E',
+ 'a', 'b', 'c', 'd', 't', 'n', 'e'};
+const char kCOntentChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '-', '$', '/', ':', '+', '.'};
} // namespace
@@ -50,7 +55,7 @@ CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter()
CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() {}
bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
- if (!pdfium::ContainsValue(START_END_CHARS, start))
+ if (!pdfium::ContainsValue(kStartEndChars, start))
return false;
m_chStart = start;
@@ -58,7 +63,7 @@ bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
}
bool CBC_OnedCodaBarWriter::SetEndChar(char end) {
- if (!pdfium::ContainsValue(START_END_CHARS, end))
+ if (!pdfium::ContainsValue(kStartEndChars, end))
return false;
m_chEnd = end;
@@ -90,8 +95,8 @@ bool CBC_OnedCodaBarWriter::FindChar(wchar_t ch, bool isContent) {
return false;
char narrow_ch = static_cast<char>(ch);
- return pdfium::ContainsValue(CONTENT_CHARS, narrow_ch) ||
- (isContent && pdfium::ContainsValue(START_END_CHARS, narrow_ch));
+ return pdfium::ContainsValue(kCOntentChars, narrow_ch) ||
+ (isContent && pdfium::ContainsValue(kStartEndChars, narrow_ch));
}
bool CBC_OnedCodaBarWriter::CheckContentValidity(
@@ -157,9 +162,8 @@ uint8_t* CBC_OnedCodaBarWriter::EncodeImpl(const ByteString& contents,
default:
break;
}
- int32_t code = 0;
- size_t len = strlen(kOnedCodaAlphabet);
- for (size_t i = 0; i < len; i++) {
+ int8_t code = 0;
+ for (size_t i = 0; i < FX_ArraySize(kOnedCodaAlphabet); i++) {
if (ch == kOnedCodaAlphabet[i]) {
code = kOnedCodaCharacterEncoding[i];
break;