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 --- xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp | 8 +++----- xfa/fxfa/fm2js/cxfa_fmexpression.cpp | 20 ++++++++++---------- xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'xfa/fxfa/fm2js') diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp index 1910e60e3e..84064efb45 100644 --- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp @@ -1139,7 +1139,7 @@ void CXFA_FM2JSContext::IsoTime2Num(CFXJSE_Value* pThis, CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); CFX_ByteString szArgString = ValueToUTF8String(argOne.get()); FX_STRSIZE pos = szArgString.Find('T', 0); - szArgString = szArgString.Mid(pos + 1, szArgString.GetLength() - (pos + 1)); + szArgString = szArgString.Right(szArgString.GetLength() - (pos + 1)); if (szArgString.IsEmpty()) { args.GetReturnValue()->SetInteger(0); return; @@ -3694,8 +3694,7 @@ void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis, CFX_WideString wsTimePattern(L"time{"); wsTimePattern += - wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) + - L"}"; + wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) + L"}"; wsPattern = wsDatePattern + wsTimePattern; } break; case XFA_VT_DATE: { @@ -3881,8 +3880,7 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, FX_STRSIZE iTChar = wsPattern.Find(L'T'); CFX_WideString wsDatePattern(L"date{" + wsPattern.Left(iTChar) + L"} "); CFX_WideString wsTimePattern( - L"time{" + - wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) + + L"time{" + wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) + L"}"); wsPattern = wsDatePattern + wsTimePattern; CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale, diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp index b201863b25..a74239ff82 100644 --- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp @@ -62,7 +62,7 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"function "; if (m_wsName.GetAt(0) == L'!') { CFX_WideString tempName = - EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1); + EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1); javascript << tempName; } else { javascript << m_wsName; @@ -75,7 +75,7 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { if (identifier.GetAt(0) == L'!') { CFX_WideString tempIdentifier = EXCLAMATION_IN_IDENTIFIER + - identifier.Mid(1, identifier.GetLength() - 1); + identifier.Right(identifier.GetLength() - 1); javascript << tempIdentifier; } else { javascript << identifier; @@ -130,7 +130,7 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideString tempName(m_wsName); if (m_wsName.GetAt(0) == L'!') { tempName = - EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1); + EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1); } javascript << tempName; javascript << L" = "; @@ -154,7 +154,7 @@ bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CFX_WideString tempName(m_wsName); if (m_wsName.GetAt(0) == L'!') { tempName = - EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1); + EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1); } javascript << tempName; javascript << L" = "; @@ -461,7 +461,7 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideString tempVariant; if (m_wsVariant.GetAt(0) == L'!') { tempVariant = EXCLAMATION_IN_IDENTIFIER + - m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1); + m_wsVariant.Right(m_wsVariant.GetLength() - 1); javascript << tempVariant; } else { tempVariant = m_wsVariant; @@ -516,7 +516,7 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CFX_WideString tempVariant; if (m_wsVariant.GetAt(0) == L'!') { tempVariant = EXCLAMATION_IN_IDENTIFIER + - m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1); + m_wsVariant.Right(m_wsVariant.GetLength() - 1); javascript << tempVariant; } else { tempVariant = m_wsVariant; @@ -583,7 +583,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_wsIdentifier.GetAt(0) == L'!') { CFX_WideString tempIdentifier = EXCLAMATION_IN_IDENTIFIER + - m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1); + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1); javascript << tempIdentifier; } else { javascript << m_wsIdentifier; @@ -615,7 +615,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_wsIdentifier.GetAt(0) == L'!') { CFX_WideString tempIdentifier = EXCLAMATION_IN_IDENTIFIER + - m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1); + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1); javascript << tempIdentifier; } else { javascript << m_wsIdentifier; @@ -640,7 +640,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { if (m_wsIdentifier.GetAt(0) == L'!') { CFX_WideString tempIdentifier = EXCLAMATION_IN_IDENTIFIER + - m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1); + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1); javascript << tempIdentifier; } else { javascript << m_wsIdentifier; @@ -671,7 +671,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { if (m_wsIdentifier.GetAt(0) == L'!') { CFX_WideString tempIdentifier = EXCLAMATION_IN_IDENTIFIER + - m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1); + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1); javascript << tempIdentifier; } else { javascript << m_wsIdentifier; diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index 1a3a125032..32876e3b65 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -181,7 +181,7 @@ bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) { tempStr = L"xfa.template"; } else if (tempStr[0] == L'!') { tempStr = - EXCLAMATION_IN_IDENTIFIER + tempStr.Mid(1, tempStr.GetLength() - 1); + EXCLAMATION_IN_IDENTIFIER + tempStr.Right(tempStr.GetLength() - 1); } javascript << tempStr; return true; -- cgit v1.2.3