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 --- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/fpdfapi/page/cpdf_streamcontentparser.cpp') diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 5f571aa8d6..288f9d57a8 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -620,7 +620,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { break; } auto word = m_pSyntax->GetWord(); - CFX_ByteString key(word.Mid(1, word.GetLength() - 1)); + CFX_ByteString key(word.Right(word.GetLength() - 1)); auto pObj = m_pSyntax->ReadNextObject(false, false, 0); if (!key.IsEmpty()) { uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; @@ -1186,7 +1186,7 @@ CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace( } if (name == "DeviceGray" || name == "DeviceCMYK" || name == "DeviceRGB") { CFX_ByteString defname = "Default"; - defname += name.Mid(7, name.GetLength() - 7); + defname += name.Right(name.GetLength() - 7); CPDF_Object* pDefObj = FindResourceObj("ColorSpace", defname); if (!pDefObj) { if (name == "DeviceGray") { @@ -1525,7 +1525,7 @@ uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData, break; case CPDF_StreamParser::Name: { auto word = syntax.GetWord(); - AddNameParam(word.Mid(1, word.GetLength() - 1)); + AddNameParam(word.Right(word.GetLength() - 1)); break; } default: -- cgit v1.2.3