summaryrefslogtreecommitdiff
path: root/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-25 09:43:52 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-25 16:58:04 +0000
commitd524e4bf80314ade4a6aedf77b8b4adaa96bfcee (patch)
tree8ced866d27eca1c14c060b1c4b538fbcba2b6179 /fxbarcode/oned/BC_OnedCodaBarWriter.cpp
parent49f8dc5b1afc4f92110bf40b7639ee1138aa7240 (diff)
downloadpdfium-d524e4bf80314ade4a6aedf77b8b4adaa96bfcee.tar.xz
Delete some CFX string ctors.
Prevent implicit construction of CFX_WideString from non-wchar_t variables. Similarly prevent implicit construction of CFX_ByteString from non-char variables. Fix up CBC_OnedCodaBarWriter which tries to do the above, and simplify code there using pdfium::ContainsValue(). Same for CPDF_FileSpec. Change-Id: I3db7125a68ef3f64c2f235d38e974767cd083dc3 Reviewed-on: https://pdfium-review.googlesource.com/4478 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxbarcode/oned/BC_OnedCodaBarWriter.cpp')
-rw-r--r--fxbarcode/oned/BC_OnedCodaBarWriter.cpp68
1 files changed, 27 insertions, 41 deletions
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index 029a6ec37c..14ffcdfc35 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -20,11 +20,13 @@
* limitations under the License.
*/
+#include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
+
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/common/BC_CommonBitArray.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/oned/BC_OneDimWriter.h"
-#include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -42,34 +44,31 @@ const char CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7',
} // namespace
-CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter() {
- m_chStart = 'A';
- m_chEnd = 'B';
- m_iWideNarrRatio = 2;
-}
+CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter()
+ : m_chStart('A'), m_chEnd('B'), m_iWideNarrRatio(2) {}
+
CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() {}
+
bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
- for (size_t i = 0; i < FX_ArraySize(START_END_CHARS); ++i) {
- if (START_END_CHARS[i] == start) {
- m_chStart = start;
- return true;
- }
- }
- return false;
+ if (!pdfium::ContainsValue(START_END_CHARS, start))
+ return false;
+
+ m_chStart = start;
+ return true;
}
bool CBC_OnedCodaBarWriter::SetEndChar(char end) {
- for (size_t i = 0; i < FX_ArraySize(START_END_CHARS); ++i) {
- if (START_END_CHARS[i] == end) {
- m_chEnd = end;
- return true;
- }
- }
- return false;
+ if (!pdfium::ContainsValue(START_END_CHARS, end))
+ return false;
+
+ m_chEnd = end;
+ return true;
}
+
void CBC_OnedCodaBarWriter::SetDataLength(int32_t length) {
m_iDataLenth = length + 2;
}
+
bool CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location) {
if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
return false;
@@ -87,27 +86,14 @@ bool CBC_OnedCodaBarWriter::SetWideNarrowRatio(int8_t ratio) {
}
bool CBC_OnedCodaBarWriter::FindChar(wchar_t ch, bool isContent) {
- if (isContent) {
- for (size_t i = 0; i < FX_ArraySize(CONTENT_CHARS); ++i) {
- if (ch == (wchar_t)CONTENT_CHARS[i]) {
- return true;
- }
- }
- for (size_t j = 0; j < FX_ArraySize(START_END_CHARS); ++j) {
- if (ch == (wchar_t)START_END_CHARS[j]) {
- return true;
- }
- }
- return false;
- } else {
- for (size_t i = 0; i < FX_ArraySize(CONTENT_CHARS); ++i) {
- if (ch == (wchar_t)CONTENT_CHARS[i]) {
- return true;
- }
- }
+ if (ch > 0x7F)
return false;
- }
+
+ char narrow_ch = static_cast<char>(ch);
+ return pdfium::ContainsValue(CONTENT_CHARS, narrow_ch) ||
+ (isContent && pdfium::ContainsValue(START_END_CHARS, narrow_ch));
}
+
bool CBC_OnedCodaBarWriter::CheckContentValidity(
const CFX_WideStringC& contents) {
return std::all_of(
@@ -204,8 +190,8 @@ uint8_t* CBC_OnedCodaBarWriter::EncodeImpl(const CFX_ByteString& contents,
CFX_WideString CBC_OnedCodaBarWriter::encodedContents(
const CFX_WideStringC& contents) {
- CFX_WideString strStart(m_chStart);
- CFX_WideString strEnd(m_chEnd);
+ CFX_WideString strStart(static_cast<wchar_t>(m_chStart));
+ CFX_WideString strEnd(static_cast<wchar_t>(m_chEnd));
return strStart + contents + strEnd;
}