Fix CBC_HighLevelEncoder method naming.
Also move one method that is only used in BC_ASCIIEncoder.cpp to that
file.
Change-Id: I8c5c4e2f6ea38635f86abe7da03cd473d42a503a
Reviewed-on: https://pdfium-review.googlesource.com/c/46691
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
index 13e567f..610fa88 100644
--- a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
@@ -40,6 +40,23 @@
return static_cast<wchar_t>((digit1 - 48) * 10 + (digit2 - 48) + 130);
}
+int32_t DetermineConsecutiveDigitCount(WideString msg, int32_t startpos) {
+ int32_t count = 0;
+ int32_t len = pdfium::base::checked_cast<int32_t>(msg.GetLength());
+ int32_t idx = startpos;
+ if (idx < len) {
+ wchar_t ch = msg[idx];
+ while (FXSYS_IsDecimalDigit(ch) && idx < len) {
+ count++;
+ idx++;
+ if (idx < len) {
+ ch = msg[idx];
+ }
+ }
+ }
+ return count;
+}
+
} // namespace
CBC_ASCIIEncoder::CBC_ASCIIEncoder() = default;
@@ -51,8 +68,7 @@
}
bool CBC_ASCIIEncoder::Encode(CBC_EncoderContext* context) {
- int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount(
- context->m_msg, context->m_pos);
+ int32_t n = DetermineConsecutiveDigitCount(context->m_msg, context->m_pos);
if (n >= 2) {
Optional<wchar_t> code = EncodeASCIIDigits(
context->m_msg[context->m_pos], context->m_msg[context->m_pos + 1]);
@@ -65,7 +81,7 @@
}
wchar_t c = context->getCurrentChar();
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ int32_t newMode = CBC_HighLevelEncoder::LookAheadTest(
context->m_msg, context->m_pos, getEncodingMode());
if (newMode != getEncodingMode()) {
switch (newMode) {
@@ -94,7 +110,7 @@
}
}
- if (CBC_HighLevelEncoder::isExtendedASCII(c)) {
+ if (CBC_HighLevelEncoder::IsExtendedASCII(c)) {
context->writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT);
context->writeCodeword(static_cast<wchar_t>(c - 128 + 1));
} else {
diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
index 9938b3e..9512547 100644
--- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
@@ -55,7 +55,7 @@
wchar_t c = context->getCurrentChar();
buffer += c;
context->m_pos++;
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ int32_t newMode = CBC_HighLevelEncoder::LookAheadTest(
context->m_msg, context->m_pos, getEncodingMode());
if (newMode != getEncodingMode()) {
context->signalEncoderChange(newMode);
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp
index 983e46b..1a2b0d6 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp
@@ -86,7 +86,7 @@
}
size_t count = buffer.GetLength();
if ((count % 3) == 0) {
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ int32_t newMode = CBC_HighLevelEncoder::LookAheadTest(
context->m_msg, context->m_pos, getEncodingMode());
if (newMode != getEncodingMode()) {
context->signalEncoderChange(newMode);
diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
index 0a6c7dc..0622be5 100644
--- a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
@@ -140,7 +140,7 @@
context->writeCodewords(encoded);
buffer.Delete(0, 4);
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ int32_t newMode = CBC_HighLevelEncoder::LookAheadTest(
context->m_msg, context->m_pos, getEncodingMode());
if (newMode != getEncodingMode()) {
context->signalEncoderChange(ASCII_ENCODATION);
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index 1c43c68..77aae7d 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -167,7 +167,7 @@
}
// static
-int32_t CBC_HighLevelEncoder::lookAheadTest(const WideString& msg,
+int32_t CBC_HighLevelEncoder::LookAheadTest(const WideString& msg,
int32_t startpos,
int32_t currentMode) {
if (startpos >= pdfium::base::checked_cast<int32_t>(msg.GetLength())) {
@@ -210,7 +210,7 @@
charsProcessed++;
if (FXSYS_IsDecimalDigit(c)) {
charCounts[ASCII_ENCODATION] += 0.5;
- } else if (isExtendedASCII(c)) {
+ } else if (IsExtendedASCII(c)) {
charCounts[ASCII_ENCODATION] = (float)ceil(charCounts[ASCII_ENCODATION]);
charCounts[ASCII_ENCODATION] += 2;
} else {
@@ -219,28 +219,28 @@
}
if (IsNativeC40(c)) {
charCounts[C40_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
+ } else if (IsExtendedASCII(c)) {
charCounts[C40_ENCODATION] += 8.0f / 3.0f;
} else {
charCounts[C40_ENCODATION] += 4.0f / 3.0f;
}
if (IsNativeText(c)) {
charCounts[TEXT_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
+ } else if (IsExtendedASCII(c)) {
charCounts[TEXT_ENCODATION] += 8.0f / 3.0f;
} else {
charCounts[TEXT_ENCODATION] += 4.0f / 3.0f;
}
if (IsNativeX12(c)) {
charCounts[X12_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
+ } else if (IsExtendedASCII(c)) {
charCounts[X12_ENCODATION] += 13.0f / 3.0f;
} else {
charCounts[X12_ENCODATION] += 10.0f / 3.0f;
}
if (IsNativeEDIFACT(c)) {
charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f;
- } else if (isExtendedASCII(c)) {
+ } else if (IsExtendedASCII(c)) {
charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f;
} else {
charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f;
@@ -304,25 +304,6 @@
}
// static
-bool CBC_HighLevelEncoder::isExtendedASCII(wchar_t ch) {
+bool CBC_HighLevelEncoder::IsExtendedASCII(wchar_t ch) {
return ch >= 128 && ch <= 255;
}
-
-// static
-int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(WideString msg,
- int32_t startpos) {
- int32_t count = 0;
- int32_t len = pdfium::base::checked_cast<int32_t>(msg.GetLength());
- int32_t idx = startpos;
- if (idx < len) {
- wchar_t ch = msg[idx];
- while (FXSYS_IsDecimalDigit(ch) && idx < len) {
- count++;
- idx++;
- if (idx < len) {
- ch = msg[idx];
- }
- }
- }
- return count;
-}
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
index a7e25fd..e246dca 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.h
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
@@ -27,12 +27,10 @@
static WideString EncodeHighLevel(const WideString& msg,
bool bAllowRectangular);
- static int32_t lookAheadTest(const WideString& msg,
+ static int32_t LookAheadTest(const WideString& msg,
int32_t startpos,
int32_t currentMode);
- static bool isExtendedASCII(wchar_t ch);
- static int32_t determineConsecutiveDigitCount(WideString msg,
- int32_t startpos);
+ static bool IsExtendedASCII(wchar_t ch);
static const wchar_t LATCH_TO_C40 = 230;
static const wchar_t LATCH_TO_BASE256 = 231;
diff --git a/fxbarcode/datamatrix/BC_X12Encoder.cpp b/fxbarcode/datamatrix/BC_X12Encoder.cpp
index e9516a3..4bbb145 100644
--- a/fxbarcode/datamatrix/BC_X12Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_X12Encoder.cpp
@@ -49,7 +49,7 @@
size_t count = buffer.GetLength();
if ((count % 3) == 0) {
WriteNextTriplet(context, &buffer);
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ int32_t newMode = CBC_HighLevelEncoder::LookAheadTest(
context->m_msg, context->m_pos, getEncodingMode());
if (newMode != getEncodingMode()) {
context->signalEncoderChange(newMode);