Fix up CBC_PDF417ErrorCorrection.
- Remove ctor/dtor since the class only has static methods.
- Make GenerateErrorCorrection() return optional.
Change-Id: Ida887df8ef47d65f6adb08d2381384cbb6c3e253
Reviewed-on: https://pdfium-review.googlesource.com/c/46554
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/pdf417/BC_PDF417.cpp b/fxbarcode/pdf417/BC_PDF417.cpp
index 330584b..abf9448 100644
--- a/fxbarcode/pdf417/BC_PDF417.cpp
+++ b/fxbarcode/pdf417/BC_PDF417.cpp
@@ -360,7 +360,7 @@
bool CBC_PDF417::GenerateBarcodeLogic(const WideStringView& msg,
int32_t errorCorrectionLevel) {
int32_t errorCorrectionCodeWords =
- CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
+ CBC_PDF417ErrorCorrection::GetErrorCorrectionCodewordCount(
errorCorrectionLevel);
if (errorCorrectionCodeWords < 0)
return false;
@@ -390,12 +390,12 @@
sb += (wchar_t)900;
WideString dataCodewords(sb);
- WideString ec;
- if (!CBC_PDF417ErrorCorrection::generateErrorCorrection(
- dataCodewords, errorCorrectionLevel, &ec)) {
+ Optional<WideString> ec = CBC_PDF417ErrorCorrection::GenerateErrorCorrection(
+ dataCodewords, errorCorrectionLevel);
+ if (!ec.has_value())
return false;
- }
- WideString fullCodewords = dataCodewords + ec;
+
+ WideString fullCodewords = dataCodewords + ec.value();
m_barcodeMatrix = pdfium::MakeUnique<CBC_BarcodeMatrix>(cols, rows);
encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel,
m_barcodeMatrix.get());
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index 074e8c4..2fdf6a5 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -122,25 +122,21 @@
} // namespace
-CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() {}
-CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() {}
-int32_t CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
+// static
+int32_t CBC_PDF417ErrorCorrection::GetErrorCorrectionCodewordCount(
int32_t errorCorrectionLevel) {
if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8)
return -1;
return 1 << (errorCorrectionLevel + 1);
}
-bool CBC_PDF417ErrorCorrection::generateErrorCorrection(
+// static
+Optional<WideString> CBC_PDF417ErrorCorrection::GenerateErrorCorrection(
const WideString& dataCodewords,
- int32_t errorCorrectionLevel,
- WideString* result) {
- ASSERT(result);
- ASSERT(result->IsEmpty());
-
- int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel);
+ int32_t errorCorrectionLevel) {
+ int32_t k = GetErrorCorrectionCodewordCount(errorCorrectionLevel);
if (k < 0)
- return false;
+ return {};
std::vector<wchar_t> ech(k);
size_t sld = dataCodewords.GetLength();
@@ -157,11 +153,12 @@
t3 = 929 - t2;
ech[0] = (wchar_t)(t3 % 929);
}
- result->Reserve(k);
+ WideString result;
+ result.Reserve(k);
for (int32_t j = k - 1; j >= 0; j--) {
if (ech[j] != 0)
ech[j] = static_cast<wchar_t>(929) - ech[j];
- *result += ech[j];
+ result += ech[j];
}
- return true;
+ return result;
}
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
index 3e28162..f5aa898 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
@@ -10,16 +10,17 @@
#include <stdint.h>
#include "core/fxcrt/fx_string.h"
+#include "third_party/base/optional.h"
class CBC_PDF417ErrorCorrection {
public:
- CBC_PDF417ErrorCorrection();
- virtual ~CBC_PDF417ErrorCorrection();
+ CBC_PDF417ErrorCorrection() = delete;
+ ~CBC_PDF417ErrorCorrection() = delete;
- static int32_t getErrorCorrectionCodewordCount(int32_t errorCorrectionLevel);
- static bool generateErrorCorrection(const WideString& dataCodewords,
- int32_t errorCorrectionLevel,
- WideString* result);
+ static int32_t GetErrorCorrectionCodewordCount(int32_t errorCorrectionLevel);
+ static Optional<WideString> GenerateErrorCorrection(
+ const WideString& dataCodewords,
+ int32_t errorCorrectionLevel);
};
#endif // FXBARCODE_PDF417_BC_PDF417ERRORCORRECTION_H_