From d7403971a25c317671e92ccc676a5f600ed223eb Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 5 Jul 2017 10:39:20 -0400 Subject: Extract comparison functions from std::lower_bound args Cleanup of code I changed earlier last week, to match the style recommended in later reviews and make it more readable. BUG=pdfium:786 Change-Id: I2ff8b980a229718e389ad1a8063bd5059aedb66c Reviewed-on: https://pdfium-review.googlesource.com/7212 Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index 8078ae9841..955b06fe93 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -520,14 +520,14 @@ bool CXFA_FMCallExpression::IsBuiltInFunc(CFX_WideTextBuf* funcName) { if (funcName->GetLength() > g_BuiltInFuncsMaxLen) return false; + auto cmpFunc = [](const wchar_t* iter, const CFX_WideString& val) -> bool { + return val.CompareNoCase(iter) > 0; + }; CFX_WideString str = funcName->MakeString(); - const wchar_t* const* pEnd = g_BuiltInFuncs + FX_ArraySize(g_BuiltInFuncs); const wchar_t* const* pMatchResult = std::lower_bound( - g_BuiltInFuncs, pEnd, str, - [](const wchar_t* iter, const CFX_WideString& val) -> bool { - return val.CompareNoCase(iter) > 0; - }); - if (pMatchResult < pEnd && !str.CompareNoCase(*pMatchResult)) { + std::begin(g_BuiltInFuncs), std::end(g_BuiltInFuncs), str, cmpFunc); + if (pMatchResult != std::end(g_BuiltInFuncs) && + !str.CompareNoCase(*pMatchResult)) { funcName->Clear(); *funcName << *pMatchResult; return true; @@ -537,11 +537,12 @@ bool CXFA_FMCallExpression::IsBuiltInFunc(CFX_WideTextBuf* funcName) { uint32_t CXFA_FMCallExpression::IsMethodWithObjParam( const CFX_WideString& methodName) { - const XFA_FMSOMMethod* result = std::lower_bound( - std::begin(gs_FMSomMethods), std::end(gs_FMSomMethods), methodName, - [](const XFA_FMSOMMethod iter, const CFX_WideString& val) { - return val.Compare(iter.m_wsSomMethodName) > 0; - }); + auto cmpFunc = [](const XFA_FMSOMMethod iter, const CFX_WideString& val) { + return val.Compare(iter.m_wsSomMethodName) > 0; + }; + const XFA_FMSOMMethod* result = + std::lower_bound(std::begin(gs_FMSomMethods), std::end(gs_FMSomMethods), + methodName, cmpFunc); if (result != std::end(gs_FMSomMethods) && !methodName.Compare(result->m_wsSomMethodName)) { return result->m_dParameters; -- cgit v1.2.3