From 9e7e95a57b7c16941d9fdc59f806c1f9e4263379 Mon Sep 17 00:00:00 2001 From: jsala Date: Tue, 21 Jun 2022 21:25:50 +0200 Subject: tdf#147021 Use std::size() instead of SAL_N_ELEMENTS() macro Change associated for by std::find_if in sqlbison.y Also change some integer by std::size_t Change-Id: I0d2100fbd7c22729da6ce0462c6cc093e0767fb4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136263 Tested-by: Jenkins Reviewed-by: Hossein --- connectivity/source/parse/sqlbison.y | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'connectivity') diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y index dd500ce2548b..59d8b2532430 100644 --- a/connectivity/source/parse/sqlbison.y +++ b/connectivity/source/parse/sqlbison.y @@ -44,7 +44,6 @@ #include #include "connectivity/dbconversion.hxx" #include -#include #include #if defined _MSC_VER @@ -4382,7 +4381,7 @@ OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const { - static IParseContext::InternationalKeyCode Intl_TokenID[] = + static IParseContext::InternationalKeyCode const Intl_TokenID[] = { InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True, InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or, @@ -4392,15 +4391,14 @@ IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection }; - sal_uInt32 nCount = SAL_N_ELEMENTS( Intl_TokenID ); - for (sal_uInt32 i = 0; i < nCount; i++) - { - OString aKey = getIntlKeywordAscii(Intl_TokenID[i]); - if (rToken.equalsIgnoreAsciiCase(aKey)) - return Intl_TokenID[i]; - } + auto const token = std::find_if(std::cbegin(Intl_TokenID), std::cend(Intl_TokenID) + , [&rToken, this](IParseContext::InternationalKeyCode const & tokenID) + { return rToken.equalsIgnoreAsciiCase(getIntlKeywordAscii(tokenID)); }); + + if (std::cend(Intl_TokenID) != token) + return *token; - return InternationalKeyCode::None; + return InternationalKeyCode::None; } @@ -4671,7 +4669,7 @@ OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pCont #if OSL_DEBUG_LEVEL > 0 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID) { - OSL_ENSURE(nRuleID < SAL_N_ELEMENTS(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!"); + OSL_ENSURE(nRuleID < std::size(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!"); return OUString::createFromAscii(yytname[nRuleID]); } #endif @@ -4681,8 +4679,8 @@ sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue) { // Search for the given name in yytname and return the index // (or UNKNOWN_RULE, if not found) - static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname); - for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++) + static sal_uInt32 const nLen = std::size(yytname)-1; + for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < nLen; ++i) { if (rValue == yytname[i]) return i; -- cgit