From a2188df09255b49ad41a89ae9b5de640d0b03126 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 1 Sep 2017 15:11:12 -0400 Subject: Cleanup usages of Mid(foo, 1), Right(1), and Left(1) Mid(foo, 1) is equivalent to [foo], if all you want is the character. Similarly Left(1) is [0]. It is faster also, since it does not need to create intermediate strings. Right(1) is a touch more tricky, since it requires something like GetLength() ? [GetLength() - 1] : 0;. A new method, Last() has been added to perform this character extraction. Multiple call sites have been updated to use more efficient/simpler syntax. There are a number of call sites that use on these patterns, but based on the surrounding context we actually need/want a string, so they have not been modified. Change-Id: I485a7f9c7b34c9bdacecada610158f996816afdd Reviewed-on: https://pdfium-review.googlesource.com/12890 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- fxbarcode/oned/BC_OnedEAN13Writer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fxbarcode/oned/BC_OnedEAN13Writer.cpp') diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index 6d8d51d495..dddb9cc24d 100644 --- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -109,7 +109,7 @@ uint8_t* CBC_OnedEAN13Writer::EncodeImpl(const CFX_ByteString& contents, return nullptr; m_iDataLenth = 13; - int32_t firstDigit = FXSYS_atoi(contents.Left(1).c_str()); + int32_t firstDigit = FXSYS_DecimalCharToInt(contents.First()); int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit]; outLength = m_codeWidth; std::unique_ptr result( @@ -122,7 +122,7 @@ uint8_t* CBC_OnedEAN13Writer::EncodeImpl(const CFX_ByteString& contents, int32_t i = 0; for (i = 1; i <= 6; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); + int32_t digit = FXSYS_DecimalCharToInt(contents[i]); if ((parities >> (6 - i) & 1) == 1) { digit += 10; } @@ -135,7 +135,7 @@ uint8_t* CBC_OnedEAN13Writer::EncodeImpl(const CFX_ByteString& contents, return nullptr; for (i = 7; i <= 12; i++) { - int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); + int32_t digit = FXSYS_DecimalCharToInt(contents[i]); pos += AppendPattern(result.get(), pos, L_PATTERNS[digit], 4, 1, e); if (e != BCExceptionNO) return nullptr; -- cgit v1.2.3