From 599f0cbe1ddc1d54828489b389b78fdffa4ce39f Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 5 Feb 2016 16:56:54 +0100 Subject: interface to new XTextSearch2 with SearchOptions2, tdf#72196 Places that had utl::TextSearch::UpgradeToSearchOptions2() introduced are worth an inspection if the new SearchAlgorithms2::WILDCARD search should be supported or at least use SearchOptions2 instead of SearchOptions to eliminate the small performance penalty that conversion involves. Change-Id: I565f73af2b551ae9ad0f488e672823dc6c5c1109 --- i18npool/source/search/i18nsearch.component | 1 + i18npool/source/search/textsearch.cxx | 68 ++++++++++++++++++++++++----- i18npool/source/search/textsearch.hxx | 15 ++++--- 3 files changed, 68 insertions(+), 16 deletions(-) (limited to 'i18npool') diff --git a/i18npool/source/search/i18nsearch.component b/i18npool/source/search/i18nsearch.component index 93bf92db6aad..ddb591f98b5f 100644 --- a/i18npool/source/search/i18nsearch.component +++ b/i18npool/source/search/i18nsearch.component @@ -21,5 +21,6 @@ prefix="i18nsearch" xmlns="http://openoffice.org/2010/uno-components"> + diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx index 57a995ee421f..d0e13e5d94fc 100644 --- a/i18npool/source/search/textsearch.cxx +++ b/i18npool/source/search/textsearch.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -112,7 +113,8 @@ TextSearch::TextSearch(const Reference < XComponentContext > & rxContext) , pRegexMatcher( nullptr ) , pWLD( nullptr ) { - SearchOptions aOpt; + SearchOptions2 aOpt; + aOpt.AlgorithmType2 = SearchAlgorithms2::ABSOLUTE; aOpt.algorithmType = SearchAlgorithms_ABSOLUTE; aOpt.searchFlag = SearchFlags::ALL_IGNORE_CASE; //aOpt.Locale = ???; @@ -127,7 +129,7 @@ TextSearch::~TextSearch() delete pJumpTable2; } -void TextSearch::setOptions( const SearchOptions& rOptions ) throw( RuntimeException, std::exception ) +void TextSearch::setOptions2( const SearchOptions2& rOptions ) throw( RuntimeException, std::exception ) { aSrchPara = rOptions; @@ -165,7 +167,7 @@ void TextSearch::setOptions( const SearchOptions& rOptions ) throw( RuntimeExcep sSrchStr = aSrchPara.searchString; // Transliterate search string. - if (aSrchPara.algorithmType == SearchAlgorithms_REGEXP) + if (aSrchPara.AlgorithmType2 == SearchAlgorithms2::REGEXP) { if (isSimpleRegexTrans( aSrchPara.transliterateFlags)) { @@ -212,15 +214,17 @@ void TextSearch::setOptions( const SearchOptions& rOptions ) throw( RuntimeExcep checkCTLEnd = (xBreak.is() && (xBreak->getScriptType(sSrchStr, sSrchStr.getLength()-1) == ScriptType::COMPLEX)); - switch( aSrchPara.algorithmType) + // Take the new SearchOptions2::AlgorithmType2 field and ignore + // SearchOptions::algorithmType + switch( aSrchPara.AlgorithmType2) { - case SearchAlgorithms_REGEXP: + case SearchAlgorithms2::REGEXP: fnForward = &TextSearch::RESrchFrwrd; fnBackward = &TextSearch::RESrchBkwrd; RESrchPrepare( aSrchPara); break; - case SearchAlgorithms_APPROXIMATE: + case SearchAlgorithms2::APPROXIMATE: fnForward = &TextSearch::ApproxSrchFrwrd; fnBackward = &TextSearch::ApproxSrchBkwrd; @@ -232,12 +236,51 @@ void TextSearch::setOptions( const SearchOptions& rOptions ) throw( RuntimeExcep break; default: + case SearchAlgorithms2::WILDCARD: /* FIXME: temporary */ + SAL_WARN("i18npool","TextSearch::setOptions2 - default what?"); + // fallthru + case SearchAlgorithms2::ABSOLUTE: fnForward = &TextSearch::NSrchFrwrd; fnBackward = &TextSearch::NSrchBkwrd; break; } } +void TextSearch::setOptions( const SearchOptions& rOptions ) throw( RuntimeException, std::exception ) +{ + sal_Int16 nAlgorithmType2; + switch (rOptions.algorithmType) + { + case SearchAlgorithms_REGEXP: + nAlgorithmType2 = SearchAlgorithms2::REGEXP; + break; + case SearchAlgorithms_APPROXIMATE: + nAlgorithmType2 = SearchAlgorithms2::APPROXIMATE; + break; + default: + SAL_WARN("i18npool","TextSearch::setOptions - default what?"); + // fallthru + case SearchAlgorithms_ABSOLUTE: + nAlgorithmType2 = SearchAlgorithms2::ABSOLUTE; + break; + } + // It would be nice if an inherited struct had a ctor that takes an + // instance of the object the struct derived from.. + SearchOptions2 aOptions2( + rOptions.algorithmType, + rOptions.searchFlag, + rOptions.searchString, + rOptions.replaceString, + rOptions.Locale, + rOptions.changedChars, + rOptions.deletedChars, + rOptions.insertedChars, + rOptions.transliterateFlags, + nAlgorithmType2 + ); + setOptions2( aOptions2); +} + sal_Int32 FindPosInSeq_Impl( const Sequence & rOff, sal_Int32 nPos ) { sal_Int32 nRet = 0, nEnd = rOff.getLength(); @@ -325,7 +368,7 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta sres = (this->*fnForward)( in_str, startPos, endPos ); } - if ( xTranslit2.is() && aSrchPara.algorithmType != SearchAlgorithms_REGEXP) + if ( xTranslit2.is() && aSrchPara.AlgorithmType2 != SearchAlgorithms2::REGEXP) { SearchResult sres2; @@ -432,7 +475,7 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st sres = (this->*fnBackward)( in_str, startPos, endPos ); } - if ( xTranslit2.is() && aSrchPara.algorithmType != SearchAlgorithms_REGEXP ) + if ( xTranslit2.is() && aSrchPara.AlgorithmType2 != SearchAlgorithms2::REGEXP ) { SearchResult sres2; @@ -776,7 +819,7 @@ SearchResult TextSearch::NSrchBkwrd( const OUString& searchStr, sal_Int32 startP return aRet; } -void TextSearch::RESrchPrepare( const css::util::SearchOptions& rOptions) +void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions) { // select the transliterated pattern string const OUString& rPatternStr = @@ -1080,9 +1123,12 @@ SearchResult TextSearch::ApproxSrchBkwrd( const OUString& searchStr, static const sal_Char cSearchImpl[] = "com.sun.star.util.TextSearch_i18n"; -static OUString getServiceName_Static() +static uno::Sequence< OUString > getServiceName_Static() { - return OUString( "com.sun.star.util.TextSearch" ); + uno::Sequence< OUString > aRet(2); + aRet[0] = "com.sun.star.util.TextSearch"; + aRet[1] = "com.sun.star.util.TextSearch2"; + return aRet; } static OUString getImplementationName_Static() diff --git a/i18npool/source/search/textsearch.hxx b/i18npool/source/search/textsearch.hxx index 5c2ef0312290..ae189c29df63 100644 --- a/i18npool/source/search/textsearch.hxx +++ b/i18npool/source/search/textsearch.hxx @@ -21,7 +21,7 @@ #define INCLUDED_I18NPOOL_SOURCE_SEARCH_TEXTSEARCH_HXX #include -#include +#include #include #include #include @@ -39,13 +39,13 @@ typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable; class TextSearch: public cppu::WeakImplHelper < - css::util::XTextSearch, + css::util::XTextSearch2, css::lang::XServiceInfo > { css::uno::Reference < css::uno::XComponentContext > m_xContext; - css::util::SearchOptions aSrchPara; + css::util::SearchOptions2 aSrchPara; OUString sSrchStr; OUString sSrchStr2; @@ -91,7 +91,7 @@ class TextSearch: public cppu::WeakImplHelper RESrchBkwrd( const OUString& searchStr, sal_Int32 startPos, sal_Int32 endPos ) throw(css::uno::RuntimeException); - void RESrchPrepare( const css::util::SearchOptions&); + void RESrchPrepare( const css::util::SearchOptions2&); // Members and methods for the "Weight Levenshtein-Distance" search int nLimit; @@ -118,7 +118,7 @@ public: virtual ~TextSearch(); - // Methods + // XTextSearch virtual void SAL_CALL setOptions( const css::util::SearchOptions& options ) throw(css::uno::RuntimeException, std::exception) override; @@ -131,6 +131,11 @@ public: sal_Int32 startPos, sal_Int32 endPos ) throw(css::uno::RuntimeException, std::exception) override; + // XTextSearch2 + virtual void SAL_CALL + setOptions2( const css::util::SearchOptions2& options ) + throw(css::uno::RuntimeException, std::exception) override; + //XServiceInfo virtual OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException, std::exception ) override; -- cgit