diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-11 08:46:08 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-11 10:54:59 +0100 |
commit | 459ee2660cba282ae988da43fdd3147a2ebce58b (patch) | |
tree | afa40cc834e0d86fb1836a3d02865d705c1a0825 /sc | |
parent | dddee125cc32f1ad5228e598a7de04e9654e65c1 (diff) |
Simplify MayBeRegExp/MayBeWildcard
Change-Id: Ibc5dc0b1157fa28035fa0d09d7e1a5d34df9e39b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131333
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/inc/interpre.hxx | 13 | ||||
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 46 |
2 files changed, 13 insertions, 46 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 5d06319b2538..47763ed8fea4 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -150,21 +150,10 @@ public: static void GlobalExit(); // called by ScGlobal::Clear() - /// Could string be a regular expression? - /// if regularExpressions are disabled the function returns false regardless - /// of the string content. - static bool MayBeRegExp( const OUString& rStr ); - - /** Could string be a wildcard (*,?,~) expression? - If wildcards are disabled the function returns false regardless of the - string content. - */ - static bool MayBeWildcard( const OUString& rStr ); - /** Detect if string should be used as regular expression or wildcard expression or literal string. */ - static utl::SearchParam::SearchType DetectSearchType( const OUString& rStr, const ScDocument& rDoc ); + static utl::SearchParam::SearchType DetectSearchType(std::u16string_view rStr, const ScDocument& rDoc ); /// Fail safe division, returning a FormulaError::DivisionByZero coded into a double /// if denominator is 0.0 diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index d79962324754..f85c2190150d 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -9910,52 +9910,30 @@ void ScInterpreter::ScErrorType_ODF() PushNA(); } -bool ScInterpreter::MayBeRegExp( const OUString& rStr ) +static bool MayBeRegExp( std::u16string_view rStr ) { - if ( rStr.isEmpty() || (rStr.getLength() == 1 && !rStr.startsWith(".")) ) + if ( rStr.empty() || (rStr.size() == 1 && rStr[0] != '.') ) return false; // single meta characters can not be a regexp // First two characters are wildcard '?' and '*' characters. - static const sal_Unicode cre[] = { '?','*','+','.','[',']','^','$','\\','<','>','(',')','|', 0 }; - const sal_Unicode* p1 = rStr.getStr(); - sal_Unicode c1; - while ( ( c1 = *p1++ ) != 0 ) - { - const sal_Unicode* p2 = cre; - while ( *p2 ) - { - if ( c1 == *p2++ ) - return true; - } - } - return false; + std::u16string_view cre(u"?*+.[]^$\\<>()|"); + return rStr.find_first_of(cre) != std::u16string_view::npos; } -bool ScInterpreter::MayBeWildcard( const OUString& rStr ) +static bool MayBeWildcard( std::u16string_view rStr ) { // Wildcards with '~' escape, if there are no wildcards then an escaped // character does not make sense, but it modifies the search pattern in an // Excel compatible wildcard search... - static const sal_Unicode cw[] = { '*','?','~', 0 }; - const sal_Unicode* p1 = rStr.getStr(); - sal_Unicode c1; - while ( ( c1 = *p1++ ) != 0 ) - { - const sal_Unicode* p2 = cw; - while ( *p2 ) - { - if ( c1 == *p2++ ) - return true; - } - } - return false; + std::u16string_view cw(u"*?~"); + return rStr.find_first_of(cw) != std::u16string_view::npos; } -utl::SearchParam::SearchType ScInterpreter::DetectSearchType( const OUString& rStr, const ScDocument& rDoc ) +utl::SearchParam::SearchType ScInterpreter::DetectSearchType( std::u16string_view rStr, const ScDocument& rDoc ) { - if (rDoc.GetDocOptions().IsFormulaWildcardsEnabled()) - return MayBeWildcard( rStr ) ? utl::SearchParam::SearchType::Wildcard : utl::SearchParam::SearchType::Normal; - if (rDoc.GetDocOptions().IsFormulaRegexEnabled()) - return MayBeRegExp( rStr ) ? utl::SearchParam::SearchType::Regexp : utl::SearchParam::SearchType::Normal; + const auto eType = rDoc.GetDocOptions().GetFormulaSearchType(); + if ((eType == utl::SearchParam::SearchType::Wildcard && MayBeWildcard(rStr)) + || (eType == utl::SearchParam::SearchType::Regexp && MayBeRegExp(rStr))) + return eType; return utl::SearchParam::SearchType::Normal; } |