LibreOffice Module i18npool (master)  1
textsearch.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_I18NPOOL_SOURCE_SEARCH_TEXTSEARCH_HXX
21 #define INCLUDED_I18NPOOL_SOURCE_SEARCH_TEXTSEARCH_HXX
22 
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/util/XTextSearch2.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 
27 #include <map>
28 #include <memory>
29 #include <mutex>
30 
31 #include <unicode/regex.h>
32 #include <unicode/unistr.h>
33 #include <unicode/uversion.h>
34 
35 namespace com::sun::star::i18n { class XBreakIterator; }
36 namespace com::sun::star::i18n { class XCharacterClassification; }
37 namespace com::sun::star::i18n { class XExtendedTransliteration; }
38 namespace com::sun::star::uno { class XComponentContext; }
39 
40 
42 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
43 
44 class TextSearch: public cppu::WeakImplHelper
45 <
46  css::util::XTextSearch2,
47  css::lang::XServiceInfo
48 >
49 {
50  std::mutex m_aMutex;
51  css::uno::Reference < css::uno::XComponentContext > m_xContext;
52 
53  css::util::SearchOptions2 aSrchPara;
54  OUString sSrchStr;
55  OUString sSrchStr2;
56 
57  mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
58 
59  css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit;
60  css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2;
61 
62  // define a function pointer for the different search methods
64  (SAL_CALL TextSearch::*FnSrch)( const OUString& searchStr,
65  sal_Int32 startPos, sal_Int32 endPos );
66 
67  FnSrch fnForward;
68  FnSrch fnBackward;
69 
70  // to fix UX regression, U+0027 matches also U+2019 in non-regex search
72 
73  // Members and methods for the normal (Boyer-Moore) search
74  std::unique_ptr<TextSearchJumpTable> pJumpTable;
75  std::unique_ptr<TextSearchJumpTable> pJumpTable2;
78  void MakeForwardTab();
79  void MakeForwardTab2();
80  void MakeBackwardTab();
81  void MakeBackwardTab2();
82  sal_Int32 GetDiff( const sal_Unicode ) const;
85  NSrchFrwrd( const OUString& searchStr,
86  sal_Int32 startPos, sal_Int32 endPos );
89  NSrchBkwrd( const OUString& searchStr,
90  sal_Int32 startPos, sal_Int32 endPos );
91 
92  // Members and methods for the regular expression search
93  std::unique_ptr<icu::RegexMatcher> pRegexMatcher;
96  RESrchFrwrd( const OUString& searchStr,
97  sal_Int32 startPos, sal_Int32 endPos );
100  RESrchBkwrd( const OUString& searchStr,
101  sal_Int32 startPos, sal_Int32 endPos );
102  void RESrchPrepare( const css::util::SearchOptions2&);
103 
104  // Members and methods for the "Weight Levenshtein-Distance" search
105  int nLimit;
106  std::unique_ptr<WLevDistance> pWLD;
107  css::uno::Reference < css::i18n::XBreakIterator > xBreak;
109  css::util::SearchResult SAL_CALL
110  ApproxSrchFrwrd( const OUString& searchStr,
111  sal_Int32 startPos, sal_Int32 endPos );
113  css::util::SearchResult SAL_CALL
114  ApproxSrchBkwrd( const OUString& searchStr,
115  sal_Int32 startPos, sal_Int32 endPos );
116 
117  // Members and methods for the wildcard search
123  css::util::SearchResult SAL_CALL
124  WildcardSrchFrwrd( const OUString& searchStr,
125  sal_Int32 startPos, sal_Int32 endPos );
127  css::util::SearchResult SAL_CALL
128  WildcardSrchBkwrd( const OUString& searchStr,
129  sal_Int32 startPos, sal_Int32 endPos );
130 
131  bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
132 
135  bool isCellStart(const OUString& searchStr, sal_Int32 nPos);
136 
137 public:
138  explicit TextSearch(
139  const css::uno::Reference < css::uno::XComponentContext >& rxContext );
140 
141  virtual ~TextSearch() override;
142 
143  // XTextSearch
144  virtual void SAL_CALL
145  setOptions( const css::util::SearchOptions& options ) override;
146  virtual css::util::SearchResult SAL_CALL
147  searchForward( const OUString& searchStr,
148  sal_Int32 startPos, sal_Int32 endPos ) override;
149  virtual css::util::SearchResult SAL_CALL
150  searchBackward( const OUString& searchStr,
151  sal_Int32 startPos, sal_Int32 endPos ) override;
152 
153  // XTextSearch2
154  virtual void SAL_CALL
155  setOptions2( const css::util::SearchOptions2& options ) override;
156 
157  //XServiceInfo
158  virtual OUString SAL_CALL getImplementationName() override;
159  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
160  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
161 };
162 
163 #endif
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< icu::RegexMatcher > pRegexMatcher
Definition: textsearch.hxx:93
std::mutex m_aMutex
Definition: textsearch.hxx:50
bool bUsePrimarySrchStr
Definition: textsearch.hxx:77
virtual void SAL_CALL setOptions2(const css::util::SearchOptions2 &options) override
Definition: textsearch.cxx:117
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::util::SearchOptions2 aSrchPara
Definition: textsearch.hxx:53
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit
Definition: textsearch.hxx:59
OUString sSrchStr2
Definition: textsearch.hxx:55
bool checkCTLEnd
Definition: textsearch.hxx:133
sal_uInt32 mcWildcardEscapeChar
Definition: textsearch.hxx:120
void MakeForwardTab()
Definition: textsearch.cxx:596
css::util::SearchResult SAL_CALL RESrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
virtual void SAL_CALL setOptions(const css::util::SearchOptions &options) override
Definition: textsearch.cxx:265
void MakeBackwardTab2()
Definition: textsearch.cxx:670
sal_Int32 GetDiff(const sal_Unicode) const
Definition: textsearch.cxx:693
void MakeBackwardTab()
Definition: textsearch.cxx:647
OUString maWildcardReversePattern2
Definition: textsearch.hxx:119
sal_uInt16 sal_Unicode
virtual ~TextSearch() override
Definition: textsearch.cxx:109
bool checkCTLStart
Definition: textsearch.hxx:133
typedef css::util::SearchResult(SAL_CALL TextSearch::*FnSrch)(const OUString &searchStr
bool bSearchApostrophe
Definition: textsearch.hxx:71
css::util::SearchResult SAL_CALL WildcardSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
css::util::SearchResult SAL_CALL ApproxSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
TextSearch(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual css::util::SearchResult SAL_CALL searchBackward(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos) override
Definition: textsearch.cxx:454
void RESrchPrepare(const css::util::SearchOptions2 &)
Definition: textsearch.cxx:858
bool IsDelimiter(const OUString &rStr, sal_Int32 nPos) const
Definition: textsearch.cxx:577
css::uno::Reference< css::i18n::XCharacterClassification > xCharClass
Definition: textsearch.hxx:57
css::util::SearchResult SAL_CALL NSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:781
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::util::SearchResult SAL_CALL searchForward(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos) override
Definition: textsearch.cxx:315
FnSrch fnBackward
Definition: textsearch.hxx:68
unsigned char sal_Bool
css::util::SearchResult SAL_CALL ApproxSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
bool bIsForwardTab
Definition: textsearch.hxx:76
OUString sSrchStr
Definition: textsearch.hxx:54
Weighted Levenshtein Distance (WLD)
Definition: levdis.hxx:133
OUString maWildcardReversePattern
Definition: textsearch.hxx:118
css::uno::Reference< css::i18n::XBreakIterator > xBreak
Definition: textsearch.hxx:107
css::util::SearchResult SAL_CALL RESrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:947
sal_Int32 startPos
Definition: textsearch.hxx:65
bool mbWildcardAllowSubstring
Definition: textsearch.hxx:121
bool isCellStart(const OUString &searchStr, sal_Int32 nPos)
Definition: textsearch.cxx:308
css::util::SearchResult SAL_CALL NSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:713
std::unique_ptr< TextSearchJumpTable > pJumpTable2
Definition: textsearch.hxx:75
std::unique_ptr< WLevDistance > pWLD
Definition: textsearch.hxx:106
std::unique_ptr< TextSearchJumpTable > pJumpTable
Definition: textsearch.hxx:74
FnSrch fnForward
Definition: textsearch.hxx:67
virtual OUString SAL_CALL getImplementationName() override
void MakeForwardTab2()
Definition: textsearch.cxx:622
sal_Int32 sal_Int32 endPos
Definition: textsearch.hxx:65
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2
Definition: textsearch.hxx:60
::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable
Definition: textsearch.hxx:41
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: textsearch.hxx:51
css::util::SearchResult SAL_CALL WildcardSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)