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 
30 #include <unicode/regex.h>
31 #include <unicode/unistr.h>
32 #include <unicode/uversion.h>
33 
34 namespace com::sun::star::i18n { class XBreakIterator; }
35 namespace com::sun::star::i18n { class XCharacterClassification; }
36 namespace com::sun::star::i18n { class XExtendedTransliteration; }
37 namespace com::sun::star::uno { class XComponentContext; }
38 
39 
40 typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
41 
43 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
44 
45 class TextSearch: public cppu::WeakImplHelper
46 <
47  css::util::XTextSearch2,
48  css::lang::XServiceInfo
49 >
50 {
51  osl::Mutex m_aMutex;
52  css::uno::Reference < css::uno::XComponentContext > m_xContext;
53 
54  css::util::SearchOptions2 aSrchPara;
55  OUString sSrchStr;
56  OUString sSrchStr2;
57 
58  mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
59 
60  css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit;
61  css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2;
62 
63  // define a function pointer for the different search methods
65  (SAL_CALL TextSearch::*FnSrch)( const OUString& searchStr,
66  sal_Int32 startPos, sal_Int32 endPos );
67 
68  FnSrch fnForward;
69  FnSrch fnBackward;
70 
71  // to fix UX regression, U+0027 matches also U+2019 in non-regex search
73 
74  // Members and methods for the normal (Boyer-Moore) search
75  std::unique_ptr<TextSearchJumpTable> pJumpTable;
76  std::unique_ptr<TextSearchJumpTable> pJumpTable2;
79  void MakeForwardTab();
80  void MakeForwardTab2();
81  void MakeBackwardTab();
82  void MakeBackwardTab2();
83  sal_Int32 GetDiff( const sal_Unicode ) const;
86  NSrchFrwrd( const OUString& searchStr,
87  sal_Int32 startPos, sal_Int32 endPos );
90  NSrchBkwrd( const OUString& searchStr,
91  sal_Int32 startPos, sal_Int32 endPos );
92 
93  // Members and methods for the regular expression search
94  std::unique_ptr<icu::RegexMatcher> pRegexMatcher;
97  RESrchFrwrd( const OUString& searchStr,
98  sal_Int32 startPos, sal_Int32 endPos );
100  css::util::SearchResult SAL_CALL
101  RESrchBkwrd( const OUString& searchStr,
102  sal_Int32 startPos, sal_Int32 endPos );
103  void RESrchPrepare( const css::util::SearchOptions2&);
104 
105  // Members and methods for the "Weight Levenshtein-Distance" search
106  int nLimit;
107  std::unique_ptr<WLevDistance> pWLD;
108  css::uno::Reference < css::i18n::XBreakIterator > xBreak;
110  css::util::SearchResult SAL_CALL
111  ApproxSrchFrwrd( const OUString& searchStr,
112  sal_Int32 startPos, sal_Int32 endPos );
114  css::util::SearchResult SAL_CALL
115  ApproxSrchBkwrd( const OUString& searchStr,
116  sal_Int32 startPos, sal_Int32 endPos );
117 
118  // Members and methods for the wildcard search
124  css::util::SearchResult SAL_CALL
125  WildcardSrchFrwrd( const OUString& searchStr,
126  sal_Int32 startPos, sal_Int32 endPos );
128  css::util::SearchResult SAL_CALL
129  WildcardSrchBkwrd( const OUString& searchStr,
130  sal_Int32 startPos, sal_Int32 endPos );
131 
132  bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
133 
136  bool isCellStart(const OUString& searchStr, sal_Int32 nPos);
137 
138 public:
139  explicit TextSearch(
140  const css::uno::Reference < css::uno::XComponentContext >& rxContext );
141 
142  virtual ~TextSearch() override;
143 
144  // XTextSearch
145  virtual void SAL_CALL
146  setOptions( const css::util::SearchOptions& options ) override;
147  virtual css::util::SearchResult SAL_CALL
148  searchForward( const OUString& searchStr,
149  sal_Int32 startPos, sal_Int32 endPos ) override;
150  virtual css::util::SearchResult SAL_CALL
151  searchBackward( const OUString& searchStr,
152  sal_Int32 startPos, sal_Int32 endPos ) override;
153 
154  // XTextSearch2
155  virtual void SAL_CALL
156  setOptions2( const css::util::SearchOptions2& options ) override;
157 
158  //XServiceInfo
159  virtual OUString SAL_CALL getImplementationName() override;
160  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
161  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
162 };
163 
164 #endif
165 
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< icu::RegexMatcher > pRegexMatcher
Definition: textsearch.hxx:94
bool bUsePrimarySrchStr
Definition: textsearch.hxx:78
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:54
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit
Definition: textsearch.hxx:60
osl::Mutex m_aMutex
Definition: textsearch.hxx:51
OUString sSrchStr2
Definition: textsearch.hxx:56
bool checkCTLEnd
Definition: textsearch.hxx:134
sal_uInt32 mcWildcardEscapeChar
Definition: textsearch.hxx:121
void MakeForwardTab()
Definition: textsearch.cxx:598
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:672
sal_Int32 GetDiff(const sal_Unicode) const
Definition: textsearch.cxx:695
void MakeBackwardTab()
Definition: textsearch.cxx:649
OUString maWildcardReversePattern2
Definition: textsearch.hxx:120
sal_uInt16 sal_Unicode
virtual ~TextSearch() override
Definition: textsearch.cxx:109
bool checkCTLStart
Definition: textsearch.hxx:134
typedef css::util::SearchResult(SAL_CALL TextSearch::*FnSrch)(const OUString &searchStr
bool bSearchApostrophe
Definition: textsearch.hxx:72
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:456
void RESrchPrepare(const css::util::SearchOptions2 &)
Definition: textsearch.cxx:860
bool IsDelimiter(const OUString &rStr, sal_Int32 nPos) const
Definition: textsearch.cxx:579
css::uno::Reference< css::i18n::XCharacterClassification > xCharClass
Definition: textsearch.hxx:58
css::util::SearchResult SAL_CALL NSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:783
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:317
FnSrch fnBackward
Definition: textsearch.hxx:69
unsigned char sal_Bool
css::util::SearchResult SAL_CALL ApproxSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
bool bIsForwardTab
Definition: textsearch.hxx:77
OUString sSrchStr
Definition: textsearch.hxx:55
Weighted Levenshtein Distance (WLD)
Definition: levdis.hxx:133
OUString maWildcardReversePattern
Definition: textsearch.hxx:119
U_ICU_NAMESPACE::UnicodeString IcuUniString
Definition: textsearch.hxx:40
css::uno::Reference< css::i18n::XBreakIterator > xBreak
Definition: textsearch.hxx:108
css::util::SearchResult SAL_CALL RESrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:949
sal_Int32 startPos
Definition: textsearch.hxx:66
bool mbWildcardAllowSubstring
Definition: textsearch.hxx:122
bool isCellStart(const OUString &searchStr, sal_Int32 nPos)
Definition: textsearch.cxx:310
css::util::SearchResult SAL_CALL NSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:715
std::unique_ptr< TextSearchJumpTable > pJumpTable2
Definition: textsearch.hxx:76
std::unique_ptr< WLevDistance > pWLD
Definition: textsearch.hxx:107
std::unique_ptr< TextSearchJumpTable > pJumpTable
Definition: textsearch.hxx:75
FnSrch fnForward
Definition: textsearch.hxx:68
virtual OUString SAL_CALL getImplementationName() override
void MakeForwardTab2()
Definition: textsearch.cxx:624
sal_Int32 sal_Int32 endPos
Definition: textsearch.hxx:66
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2
Definition: textsearch.hxx:61
::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable
Definition: textsearch.hxx:42
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: textsearch.hxx:52
css::util::SearchResult SAL_CALL WildcardSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)