From e7a99de4f711302d57fe22682a9a8c3cfddb458c Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 28 Jul 2017 14:07:04 -0400 Subject: Convert calls to Mid() to Left() or Right() if possible The various string/byte classes support Mid(), Left(), and Right() for extracting substrings. Mid() can handle all possible cases, but Left() and Right() are useful for common cases and more explicit about what is going on. Calls like Mid(offset, length - offset) can be converted to Right(length - offset). Calls like Mid(0, length) can be converted to Left(length). If the substring being extracted does not extend all the way to one of the edges of the string, then Mid() still needs to be used. BUG=pdfium:828 Change-Id: I2ec46ad3d71aac0f7b513e103c69cbe8c854cf62 Reviewed-on: https://pdfium-review.googlesource.com/9510 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- fxbarcode/cbc_ean13.cpp | 2 +- fxbarcode/cbc_ean8.cpp | 2 +- fxbarcode/cbc_upca.cpp | 2 +- fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 7 +++---- fxbarcode/oned/BC_OnedEAN13Writer.cpp | 4 ++-- fxbarcode/oned/BC_OnedEAN8Writer.cpp | 2 +- fxbarcode/oned/BC_OnedUPCAWriter.cpp | 2 +- fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 4 ++-- 8 files changed, 12 insertions(+), 13 deletions(-) (limited to 'fxbarcode') diff --git a/fxbarcode/cbc_ean13.cpp b/fxbarcode/cbc_ean13.cpp index 1c57a877f2..ac08a9d53e 100644 --- a/fxbarcode/cbc_ean13.cpp +++ b/fxbarcode/cbc_ean13.cpp @@ -45,7 +45,7 @@ CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) { encodeContents = byteString.UTF8Decode(); } if (length > 13) - encodeContents = encodeContents.Mid(0, 13); + encodeContents = encodeContents.Left(13); return encodeContents; } diff --git a/fxbarcode/cbc_ean8.cpp b/fxbarcode/cbc_ean8.cpp index 3b4369e80f..ce2cf2ba79 100644 --- a/fxbarcode/cbc_ean8.cpp +++ b/fxbarcode/cbc_ean8.cpp @@ -43,7 +43,7 @@ CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { encodeContents += wchar_t(checksum - 0 + '0'); } if (length > 8) - encodeContents = encodeContents.Mid(0, 8); + encodeContents = encodeContents.Left(8); return encodeContents; } diff --git a/fxbarcode/cbc_upca.cpp b/fxbarcode/cbc_upca.cpp index 6c2e08a9fb..85b5d549ab 100644 --- a/fxbarcode/cbc_upca.cpp +++ b/fxbarcode/cbc_upca.cpp @@ -44,7 +44,7 @@ CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) { encodeContents = byteString.UTF8Decode(); } if (length > 12) - encodeContents = encodeContents.Mid(0, 12); + encodeContents = encodeContents.Left(12); return encodeContents; } diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index ec527d29a8..6034173ee4 100644 --- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -76,13 +76,12 @@ CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, return CFX_WideString(); context.setAllowRectangular(allowRectangular); - if ((msg.Mid(0, 6) == MACRO_05_HEADER) && - (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { + if ((msg.Left(6) == MACRO_05_HEADER) && (msg.Right(1) == MACRO_TRAILER)) { context.writeCodeword(MACRO_05); context.setSkipAtEnd(2); context.m_pos += 6; - } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) && - (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { + } else if ((msg.Left(6) == MACRO_06_HEADER) && + (msg.Right(1) == MACRO_TRAILER)) { context.writeCodeword(MACRO_06); context.setSkipAtEnd(2); context.m_pos += 6; diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index 0e4bab9518..6f1d957a01 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.Mid(0, 1).c_str()); + int32_t firstDigit = FXSYS_atoi(contents.Left(1).c_str()); int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit]; outLength = m_codeWidth; std::unique_ptr result( @@ -219,7 +219,7 @@ bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, static_cast(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } - tempStr = str.Mid(0, 1); + tempStr = str.Left(1); iLen = tempStr.GetLength(); strWidth = multiple * 7; strWidth = (int32_t)(strWidth * m_outputHScale); diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp index f891c08fc6..9a85f814a7 100644 --- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp @@ -159,7 +159,7 @@ bool CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents, CFX_ByteString str = FX_UTF8Encode(contents); int32_t iLength = str.GetLength(); std::vector charpos(iLength); - CFX_ByteString tempStr = str.Mid(0, 4); + CFX_ByteString tempStr = str.Left(4); int32_t iLen = tempStr.GetLength(); int32_t strWidth = 7 * multiple * 4; float blank = 0.0; diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp index 78ada1783a..13514eb53f 100644 --- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp @@ -183,7 +183,7 @@ bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, static_cast(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } - tempStr = str.Mid(0, 1); + tempStr = str.Left(1); iLen = tempStr.GetLength(); strWidth = (float)multiple * 7; strWidth = strWidth * m_outputHScale; diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index 955e2c7295..cad70b81c5 100644 --- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -432,7 +432,7 @@ void SplitString(const CFX_ByteString& content, index += 2; } if (index) - result->push_back({CBC_QRCoderMode::sGBK, content.Mid(0, index)}); + result->push_back({CBC_QRCoderMode::sGBK, content.Left(index)}); if (index >= content.GetLength()) return; @@ -479,7 +479,7 @@ void SplitString(const CFX_ByteString& content, } flag = index; if (index < content.GetLength()) - SplitString(content.Mid(index, content.GetLength() - index), result); + SplitString(content.Right(content.GetLength() - index), result); } CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content, -- cgit v1.2.3