[Libreoffice-commits] core.git: 2 commits - basic/source cui/source editeng/source forms/source i18npool/source include/unotools offapi/com offapi/UnoApi_offapi.mk reportdesign/source sc/source svx/source sw/source unotools/source vcl/source

Eike Rathke erack at redhat.com
Fri Feb 5 16:03:31 UTC 2016


 basic/source/runtime/runtime.cxx                      |    2 
 cui/source/options/optaboutconfig.cxx                 |    2 
 editeng/source/editeng/impedit4.cxx                   |    2 
 forms/source/xforms/computedexpression.cxx            |    2 
 i18npool/source/search/i18nsearch.component           |    1 
 i18npool/source/search/textsearch.cxx                 |   68 +++++++++++++--
 i18npool/source/search/textsearch.hxx                 |   15 ++-
 include/unotools/textsearch.hxx                       |   23 +++--
 offapi/UnoApi_offapi.mk                               |    4 
 offapi/com/sun/star/util/SearchAlgorithms2.idl        |   37 ++++++++
 offapi/com/sun/star/util/SearchOptions2.idl           |   32 +++++++
 offapi/com/sun/star/util/TextSearch2.idl              |   39 +++++++++
 offapi/com/sun/star/util/XTextSearch2.idl             |   32 +++++++
 reportdesign/source/ui/inspection/GeometryHandler.cxx |    6 -
 sc/source/core/data/table6.cxx                        |    2 
 svx/source/form/fmsrcimp.cxx                          |    2 
 sw/source/core/crsr/findattr.cxx                      |    2 
 sw/source/core/crsr/findtxt.cxx                       |    7 -
 unotools/source/i18n/textsearch.cxx                   |   78 ++++++++++++++----
 vcl/source/edit/xtextedt.cxx                          |    2 
 20 files changed, 305 insertions(+), 53 deletions(-)

New commits:
commit 599f0cbe1ddc1d54828489b389b78fdffa4ce39f
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Feb 5 16:56:54 2016 +0100

    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

diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 6535118..e92c0a1 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -1569,7 +1569,7 @@ void SbiRuntime::StepLIKE()
         aSearchOpt.transliterateFlags |= css::i18n::TransliterationModules_IGNORE_CASE;
     }
     SbxVariable* pRes = new SbxVariable;
-    utl::TextSearch aSearch(aSearchOpt);
+    utl::TextSearch aSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOpt));
     sal_Int32 nStart=0, nEnd=value.getLength();
     bool bRes = aSearch.SearchForward(value, &nStart, &nEnd);
     pRes->PutBool( bRes );
diff --git a/cui/source/options/optaboutconfig.cxx b/cui/source/options/optaboutconfig.cxx
index bf59651..85dc3f8 100644
--- a/cui/source/options/optaboutconfig.cxx
+++ b/cui/source/options/optaboutconfig.cxx
@@ -833,7 +833,7 @@ IMPL_LINK_NOARG_TYPED( CuiAboutConfigTabPage, SearchHdl_Impl, Button*, void)
     else
     {
         m_options.searchString = m_pSearchEdit->GetText();
-        utl::TextSearch textSearch( m_options );
+        utl::TextSearch textSearch( utl::TextSearch::UpgradeToSearchOptions2( m_options) );
         for (auto const& it : m_prefBoxEntries)
         {
             sal_Int32 endPos, startPos = 0;
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index 3a57c5d..6544d80 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -2622,7 +2622,7 @@ bool ImpEditEngine::ImpSearch( const SvxSearchItem& rSearchItem,
         nEndNode = bBack ? 0 : aEditDoc.Count()-1;
     }
 
-    utl::TextSearch aSearcher( aSearchOptions );
+    utl::TextSearch aSearcher( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions) );
 
     // iterate over the paragraphs ...
     for ( sal_Int32 nNode = nStartNode;
diff --git a/forms/source/xforms/computedexpression.cxx b/forms/source/xforms/computedexpression.cxx
index 08fc751..3432986 100644
--- a/forms/source/xforms/computedexpression.cxx
+++ b/forms/source/xforms/computedexpression.cxx
@@ -91,7 +91,7 @@ bool ComputedExpression::_checkExpression( const sal_Char* pExpression ) const
     SearchOptions aSearchOptions;
     aSearchOptions.algorithmType = SearchAlgorithms_REGEXP;
     aSearchOptions.searchString = OUString( pExpression, strlen(pExpression), RTL_TEXTENCODING_ASCII_US );
-    utl::TextSearch aTextSearch( aSearchOptions );
+    utl::TextSearch aTextSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions) );
 
     sal_Int32 nLength =  msExpression.getLength();
     sal_Int32 nStart = 0;
diff --git a/i18npool/source/search/i18nsearch.component b/i18npool/source/search/i18nsearch.component
index 93bf92d..ddb591f 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">
   <implementation name="com.sun.star.util.TextSearch_i18n">
     <service name="com.sun.star.util.TextSearch"/>
+    <service name="com.sun.star.util.TextSearch2"/>
   </implementation>
 </component>
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 57a995ee..d0e13e5 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -24,6 +24,7 @@
 #include <comphelper/processfactory.hxx>
 #include <com/sun/star/i18n/BreakIterator.hpp>
 #include <com/sun/star/i18n/UnicodeType.hpp>
+#include <com/sun/star/util/SearchAlgorithms2.hpp>
 #include <com/sun/star/util/SearchFlags.hpp>
 #include <com/sun/star/i18n/WordType.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
@@ -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 <sal_Int32>& 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 5c2ef03..ae189c2 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 <cppuhelper/implbase.hxx>
-#include <com/sun/star/util/XTextSearch.hpp>
+#include <com/sun/star/util/XTextSearch2.hpp>
 #include <com/sun/star/i18n/XBreakIterator.hpp>
 #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
 #include <com/sun/star/i18n/XCharacterClassification.hpp>
@@ -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;
diff --git a/include/unotools/textsearch.hxx b/include/unotools/textsearch.hxx
index 20c9e65..7ddfbf0 100644
--- a/include/unotools/textsearch.hxx
+++ b/include/unotools/textsearch.hxx
@@ -25,8 +25,8 @@
 #include <rtl/ustring.hxx>
 #include <com/sun/star/uno/Reference.h>
 #include <com/sun/star/lang/Locale.hpp>
-#include <com/sun/star/util/XTextSearch.hpp>
-#include <com/sun/star/util/SearchOptions.hpp>
+#include <com/sun/star/util/XTextSearch2.hpp>
+#include <com/sun/star/util/SearchOptions2.hpp>
 
 class CharClass;
 
@@ -47,7 +47,7 @@ namespace utl
 class UNOTOOLS_DLLPUBLIC SearchParam
 {
 public:
-    enum SearchType{ SRCH_NORMAL, SRCH_REGEXP, SRCH_LEVDIST };
+    enum SearchType{ SRCH_NORMAL, SRCH_REGEXP, SRCH_LEVDIST, SRCH_WILDCARD };
 
 private:
     OUString sSrchStr;            // the search string
@@ -100,15 +100,16 @@ public:
 //      - ordinary text (Bayer/Moore)
 //      - regular expressions
 //      - weighted Levenshtein distance
+//      - wildcards '*' and '?'
 
 //  This class allows forward and backward searching!
 
 class UNOTOOLS_DLLPUBLIC TextSearch
 {
-    static css::uno::Reference< css::util::XTextSearch >
-        getXTextSearch( const css::util::SearchOptions& rPara );
+    static css::uno::Reference< css::util::XTextSearch2 >
+        getXTextSearch( const css::util::SearchOptions2& rPara );
 
-    css::uno::Reference < css::util::XTextSearch >
+    css::uno::Reference < css::util::XTextSearch2 >
             xTextSearch;
 
     void Init( const SearchParam & rParam,
@@ -120,7 +121,7 @@ public:
     TextSearch( const SearchParam & rPara, LanguageType nLanguage );
     TextSearch( const SearchParam & rPara, const CharClass& rCClass );
 
-    TextSearch( const css::util::SearchOptions& rPara );
+    TextSearch( const css::util::SearchOptions2& rPara );
     ~TextSearch();
 
     /* search in the (selected) text the search string:
@@ -149,12 +150,18 @@ public:
                         sal_Int32* pStart, sal_Int32* pEnd,
                         css::util::SearchResult* pRes = nullptr );
 
-    void SetLocale( const css::util::SearchOptions& rOpt,
+    void SetLocale( const css::util::SearchOptions2& rOpt,
                     const css::lang::Locale& rLocale );
 
     /* replace back references in the replace string by the sub expressions from the search result */
     void ReplaceBackReferences( OUString& rReplaceStr, const OUString &rStr, const css::util::SearchResult& rResult );
 
+    /** Upgrade SearchOptions to SearchOptions2 for places that don't handle
+        SearchOptions2 yet. Better fix your module if you want to support
+        wildcard search.
+     */
+    static css::util::SearchOptions2 UpgradeToSearchOptions2( const css::util::SearchOptions& rOptions );
+
 };
 
 }   // namespace utl
diff --git a/reportdesign/source/ui/inspection/GeometryHandler.cxx b/reportdesign/source/ui/inspection/GeometryHandler.cxx
index c234c0f..da25217 100644
--- a/reportdesign/source/ui/inspection/GeometryHandler.cxx
+++ b/reportdesign/source/ui/inspection/GeometryHandler.cxx
@@ -1858,13 +1858,13 @@ bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< repo
         for (; aIter != aDeEnd; ++aIter)
         {
             aSearchOptions.searchString = aIter->m_sSearchString;
-            utl::TextSearch aTextSearch(aSearchOptions);
+            utl::TextSearch aTextSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions));
             sal_Int32 start = 0;
             sal_Int32 end = sFormula.getLength();
             if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.getLength()) // default function found
             {
                 aSearchOptions.searchString = "\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]";
-                utl::TextSearch aDataSearch(aSearchOptions);
+                utl::TextSearch aDataSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions));
                 aDataSearch.SearchForward(sFormula,&start,&end );
                 ++start;
                 _rDataField = sFormula.copy(start,end-start-1);
@@ -2075,7 +2075,7 @@ bool GeometryHandler::impl_isCounterFunction_throw(const OUString& _sQuotedFunct
             aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
             aSearchOptions.searchFlag = 0x00000100;
             aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
-            utl::TextSearch aTextSearch(aSearchOptions);
+            utl::TextSearch aTextSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions));
             sal_Int32 start = 0;
             sal_Int32 end = sFormula.getLength();
             if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.getLength()) // counter function found
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 512bbd3..d99fa42 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -744,7 +744,7 @@ bool ScTable::SearchAndReplace(
                     ( css::i18n::TransliterationModules_IGNORE_CASE |
                       css::i18n::TransliterationModules_IGNORE_WIDTH );
 
-            pSearchText = new utl::TextSearch( aSearchOptions );
+            pSearchText = new utl::TextSearch( utl::TextSearch::UpgradeToSearchOptions2( aSearchOptions) );
 
             if (nCommand == SvxSearchCmd::FIND)
                 bFound = Search(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc);
diff --git a/svx/source/form/fmsrcimp.cxx b/svx/source/form/fmsrcimp.cxx
index 1d35cfa..caf0bd2 100644
--- a/svx/source/form/fmsrcimp.cxx
+++ b/svx/source/form/fmsrcimp.cxx
@@ -568,7 +568,7 @@ FmSearchEngine::SEARCH_RESULT FmSearchEngine::SearchRegularApprox(const OUString
     }
     aParam.searchString = strExpression;
     aParam.Locale = SvtSysLocale().GetLanguageTag().getLocale();
-    ::utl::TextSearch aLocalEngine(aParam);
+    ::utl::TextSearch aLocalEngine( utl::TextSearch::UpgradeToSearchOptions2( aParam));
 
 
     bool bFound = false;
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 3cbd168..c8f402a 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -1117,7 +1117,7 @@ int SwFindParaAttr::Find( SwPaM* pCursor, SwMoveFn fnMove, const SwPaM* pRegion,
 
                 aTmp.Locale = SvtSysLocale().GetLanguageTag().getLocale();
 
-                pSText = new utl::TextSearch( aTmp );
+                pSText = new utl::TextSearch( utl::TextSearch::UpgradeToSearchOptions2( aTmp) );
             }
 
             // TODO: searching for attributes in Outliner text?!
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index caa436b..61943ac 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -540,7 +540,7 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSText,
                 {
                     const lang::Locale aLocale(
                             g_pBreakIt->GetLocale( eCurrLang ) );
-                    rSText.SetLocale( rSearchOpt, aLocale );
+                    rSText.SetLocale( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt), aLocale );
                     eLastLang = eCurrLang;
                 }
             }
@@ -635,7 +635,8 @@ struct SwFindParaText : public SwFindParas
     bool m_bSearchInNotes;
 
     SwFindParaText( const SearchOptions& rOpt, bool bSearchInNotes, bool bRepl, SwCursor& rCursor )
-        : m_rSearchOpt( rOpt ), m_rCursor( rCursor ), m_aSText( rOpt ), m_bReplace( bRepl ), m_bSearchInNotes( bSearchInNotes )
+        : m_rSearchOpt( rOpt ), m_rCursor( rCursor ), m_aSText( utl::TextSearch::UpgradeToSearchOptions2( rOpt) ),
+        m_bReplace( bRepl ), m_bSearchInNotes( bSearchInNotes )
     {}
     virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, bool bInReadOnly ) override;
     virtual bool IsReplaceMode() const override;
@@ -749,7 +750,7 @@ OUString *ReplaceBackReferences( const SearchOptions& rSearchOpt, SwPaM* pPam )
         const SwContentNode* pTextNode = pPam->GetContentNode();
         if( pTextNode && pTextNode->IsTextNode() && pTextNode == pPam->GetContentNode( false ) )
         {
-            utl::TextSearch aSText( rSearchOpt );
+            utl::TextSearch aSText( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt) );
             const OUString& rStr = pTextNode->GetTextNode()->GetText();
             sal_Int32 nStart = pPam->Start()->nContent.GetIndex();
             sal_Int32 nEnd = pPam->End()->nContent.GetIndex();
diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx
index d1b4678..10919be 100644
--- a/unotools/source/i18n/textsearch.cxx
+++ b/unotools/source/i18n/textsearch.cxx
@@ -19,7 +19,8 @@
 
 #include <i18nlangtag/languagetag.hxx>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/util/TextSearch.hpp>
+#include <com/sun/star/util/TextSearch2.hpp>
+#include <com/sun/star/util/SearchAlgorithms2.hpp>
 #include <com/sun/star/util/SearchFlags.hpp>
 #include <com/sun/star/i18n/TransliterationModules.hpp>
 #include <sal/log.hxx>
@@ -78,9 +79,11 @@ SearchParam::SearchParam( const SearchParam& rParam )
 
 SearchParam::~SearchParam() {}
 
-static bool lcl_Equals( const SearchOptions& rSO1, const SearchOptions& rSO2 )
+static bool lcl_Equals( const SearchOptions2& rSO1, const SearchOptions2& rSO2 )
 {
-    return rSO1.algorithmType == rSO2.algorithmType &&
+    return
+        rSO1.AlgorithmType2 == rSO2.AlgorithmType2 &&
+        rSO1.algorithmType == rSO2.algorithmType &&
         rSO1.searchFlag == rSO2.searchFlag &&
         rSO1.searchString.equals(rSO2.searchString) &&
         rSO1.replaceString.equals(rSO2.replaceString) &&
@@ -98,15 +101,15 @@ namespace
     struct CachedTextSearch
     {
         ::osl::Mutex mutex;
-        css::util::SearchOptions Options;
-        css::uno::Reference< css::util::XTextSearch > xTextSearch;
+        css::util::SearchOptions2 Options;
+        css::uno::Reference< css::util::XTextSearch2 > xTextSearch;
     };
 
     struct theCachedTextSearch
         : public rtl::Static< CachedTextSearch, theCachedTextSearch > {};
 }
 
-Reference<XTextSearch> TextSearch::getXTextSearch( const SearchOptions& rPara )
+Reference<XTextSearch2> TextSearch::getXTextSearch( const SearchOptions2& rPara )
 {
     CachedTextSearch &rCache = theCachedTextSearch::get();
 
@@ -116,8 +119,8 @@ Reference<XTextSearch> TextSearch::getXTextSearch( const SearchOptions& rPara )
         return rCache.xTextSearch;
 
     Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
-    rCache.xTextSearch.set( ::TextSearch::create(xContext) );
-    rCache.xTextSearch->setOptions( rPara );
+    rCache.xTextSearch.set( ::TextSearch2::create(xContext) );
+    rCache.xTextSearch->setOptions2( rPara );
     rCache.Options = rPara;
 
     return rCache.xTextSearch;
@@ -137,20 +140,61 @@ TextSearch::TextSearch(const SearchParam & rParam, const CharClass& rCClass )
     Init( rParam, rCClass.getLanguageTag().getLocale() );
 }
 
-TextSearch::TextSearch( const SearchOptions& rPara )
+TextSearch::TextSearch( const SearchOptions2& rPara )
 {
     xTextSearch = getXTextSearch( rPara );
 }
 
+css::util::SearchOptions2 TextSearch::UpgradeToSearchOptions2( const css::util::SearchOptions& rOptions )
+{
+    sal_Int16 nAlgorithmType2;
+    switch (rOptions.algorithmType)
+    {
+        case SearchAlgorithms_REGEXP:
+            nAlgorithmType2 = SearchAlgorithms2::REGEXP;
+            break;
+        case SearchAlgorithms_APPROXIMATE:
+            nAlgorithmType2 = SearchAlgorithms2::APPROXIMATE;
+            break;
+        default:
+            assert(!"utl::TextSearch::UpgradeToSearchOptions2 - 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
+            );
+    return aOptions2;
+}
+
 void TextSearch::Init( const SearchParam & rParam,
                         const css::lang::Locale& rLocale )
 {
-    // convert SearchParam to the UNO SearchOptions
-    SearchOptions aSOpt;
+    // convert SearchParam to the UNO SearchOptions2
+    SearchOptions2 aSOpt;
 
     switch( rParam.GetSrchType() )
     {
+    case SearchParam::SRCH_WILDCARD:
+        aSOpt.AlgorithmType2 = SearchAlgorithms2::WILDCARD;
+        aSOpt.algorithmType = static_cast<SearchAlgorithms>(-1);    // no old enum for that
+        break;
+
     case SearchParam::SRCH_REGEXP:
+        aSOpt.AlgorithmType2 = SearchAlgorithms2::REGEXP;
         aSOpt.algorithmType = SearchAlgorithms_REGEXP;
         if( rParam.IsSrchInSelection() )
             aSOpt.searchFlag |= SearchFlags::REG_NOT_BEGINOFLINE |
@@ -158,6 +202,7 @@ void TextSearch::Init( const SearchParam & rParam,
         break;
 
     case SearchParam::SRCH_LEVDIST:
+        aSOpt.AlgorithmType2 = SearchAlgorithms2::APPROXIMATE;
         aSOpt.algorithmType = SearchAlgorithms_APPROXIMATE;
         aSOpt.changedChars = rParam.GetLEVOther();
         aSOpt.deletedChars = rParam.GetLEVLonger();
@@ -166,8 +211,11 @@ void TextSearch::Init( const SearchParam & rParam,
             aSOpt.searchFlag |= SearchFlags::LEV_RELAXED;
         break;
 
-//  case SearchParam::SRCH_NORMAL:
     default:
+        assert(!"default what?");
+        // fallthru
+    case SearchParam::SRCH_NORMAL:
+        aSOpt.AlgorithmType2 = SearchAlgorithms2::ABSOLUTE;
         aSOpt.algorithmType = SearchAlgorithms_ABSOLUTE;
         if( rParam.IsSrchWordOnly() )
             aSOpt.searchFlag |= SearchFlags::NORM_WORD_ONLY;
@@ -186,11 +234,11 @@ void TextSearch::Init( const SearchParam & rParam,
     xTextSearch = getXTextSearch( aSOpt );
 }
 
-void TextSearch::SetLocale( const css::util::SearchOptions& rOptions,
+void TextSearch::SetLocale( const css::util::SearchOptions2& rOptions,
                             const css::lang::Locale& rLocale )
 {
-    // convert SearchParam to the UNO SearchOptions
-    SearchOptions aSOpt( rOptions );
+    // convert SearchParam to the UNO SearchOptions2
+    SearchOptions2 aSOpt( rOptions );
     aSOpt.Locale = rLocale;
 
     xTextSearch = getXTextSearch( aSOpt );
diff --git a/vcl/source/edit/xtextedt.cxx b/vcl/source/edit/xtextedt.cxx
index 690cd8d..950ab6d 100644
--- a/vcl/source/edit/xtextedt.cxx
+++ b/vcl/source/edit/xtextedt.cxx
@@ -158,7 +158,7 @@ bool ExtTextEngine::Search( TextSelection& rSel, const util::SearchOptions& rSea
 
     util::SearchOptions aOptions( rSearchOptions );
     aOptions.Locale = Application::GetSettings().GetLanguageTag().getLocale();
-    utl::TextSearch aSearcher( aOptions );
+    utl::TextSearch aSearcher( utl::TextSearch::UpgradeToSearchOptions2( aOptions));
 
     // iterate over the paragraphs
     for ( sal_uInt32 nNode = nStartNode;
commit 4c4976f717b3ddce68a872dffc2079ae49c41616
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Feb 4 19:06:39 2016 +0100

    SearchAlgorithms2, SearchOptions2, XTextSearch2, TextSearch2; tdf#72196
    
    Change-Id: Ie6da8994451deca5577503e116281441c6358a6d

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index cd23fbf..5346f26 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -444,6 +444,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/util,\
 	PathSubstitution \
 	PathSettings \
 	TextSearch \
+	TextSearch2 \
 	theOfficeInstallationDirectories \
 	UriAbbreviation \
 	URLTransformer \
@@ -4090,8 +4091,10 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\
 	NumberFormat \
 	RevisionTag \
 	SearchAlgorithms \
+	SearchAlgorithms2 \
 	SearchFlags \
 	SearchOptions \
+	SearchOptions2 \
 	SearchResult \
 	SortField \
 	SortFieldType \
@@ -4154,6 +4157,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\
 	XStringSubstitution \
 	XStringWidth \
 	XTextSearch \
+	XTextSearch2 \
 	XTimeStamped \
 	XURLTransformer \
 	XUniqueIDFactory \
diff --git a/offapi/com/sun/star/util/SearchAlgorithms2.idl b/offapi/com/sun/star/util/SearchAlgorithms2.idl
new file mode 100644
index 0000000..68906b1
--- /dev/null
+++ b/offapi/com/sun/star/util/SearchAlgorithms2.idl
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __com_sun_star_util_SearchAlgorithms2_idl__
+#define __com_sun_star_util_SearchAlgorithms2_idl__
+
+module com { module sun { module star { module util {
+
+/** Constants that define the search algorithm to be used with
+    com::sun::star::util::SearchOptions2
+ */
+published constants SearchAlgorithms2
+{
+    /// Literal
+    const short ABSOLUTE = 1;
+
+    /// Regular expression
+    const short REGEXP = 2;
+
+    /// Weighted Levenshtein Distance
+    const short APPROXIMATE = 3;
+
+    /// Wildcards '*' and '?' and escape character '~'
+    const short WILDCARD = 4;
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/util/SearchOptions2.idl b/offapi/com/sun/star/util/SearchOptions2.idl
new file mode 100644
index 0000000..7209736
--- /dev/null
+++ b/offapi/com/sun/star/util/SearchOptions2.idl
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __com_sun_star_util_SearchOptions2_idl__
+#define __com_sun_star_util_SearchOptions2_idl__
+
+
+#include <com/sun/star/util/SearchOptions.idl>
+
+
+module com { module sun { module star { module util {
+
+
+published struct SearchOptions2 : com::sun::star::util::SearchOptions {
+    /** Search type, one of com::sun::star::util::SearchAlgorithms2
+        constants. This is preferred over the content of the
+        SearchAlgorithms SearchOptions::algorithmType enum field.
+     */
+    short   AlgorithmType2;
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/util/TextSearch2.idl b/offapi/com/sun/star/util/TextSearch2.idl
new file mode 100644
index 0000000..e8db00d
--- /dev/null
+++ b/offapi/com/sun/star/util/TextSearch2.idl
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef __com_sun_star_util_TextSearch2_idl__
+#define __com_sun_star_util_TextSearch2_idl__
+
+#include <com/sun/star/util/XTextSearch2.idl>
+
+
+module com {  module sun {  module star {  module util {
+
+
+/** search a string with a defined algorithm in another string.
+
+    <p>It is possible to search forward or backward in the string.
+*/
+published service TextSearch2 : XTextSearch2;
+
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/util/XTextSearch2.idl b/offapi/com/sun/star/util/XTextSearch2.idl
new file mode 100644
index 0000000..6f8c20a
--- /dev/null
+++ b/offapi/com/sun/star/util/XTextSearch2.idl
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __com_sun_star_util_XTextSearch2_idl__
+#define __com_sun_star_util_XTextSearch2_idl__
+
+
+#include <com/sun/star/util/XTextSearch.idl>
+
+
+module com { module sun { module star { module util {
+
+/** enables an object to search in its content.
+ */
+published interface XTextSearch2 : com::sun::star::util::XTextSearch
+{
+    /** set the options for the forward or backward search.
+     */
+    void setOptions2 ([in] SearchOptions2 options);
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list