Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / i18npool / source / search / textsearch.hxx
blobaa4c8f522f86e80845661000eea2df7c184a1b89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_I18NPOOL_SOURCE_SEARCH_TEXTSEARCH_HXX
21 #define INCLUDED_I18NPOOL_SOURCE_SEARCH_TEXTSEARCH_HXX
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/util/XTextSearch2.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <map>
28 #include <memory>
30 #include <unicode/regex.h>
31 #include <unicode/unistr.h>
32 #include <unicode/uversion.h>
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; }
40 typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
42 class WLevDistance;
43 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
45 class TextSearch: public cppu::WeakImplHelper
47 css::util::XTextSearch2,
48 css::lang::XServiceInfo
51 osl::Mutex m_aMutex;
52 css::uno::Reference < css::uno::XComponentContext > m_xContext;
54 css::util::SearchOptions2 aSrchPara;
55 OUString sSrchStr;
56 OUString sSrchStr2;
58 mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
60 css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit;
61 css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2;
63 // define a function pointer for the different search methods
64 typedef css::util::SearchResult
65 (SAL_CALL TextSearch:: *FnSrch)( const OUString& searchStr,
66 sal_Int32 startPos, sal_Int32 endPos );
68 FnSrch fnForward;
69 FnSrch fnBackward;
71 // Members and methods for the normal (Boyer-Moore) search
72 std::unique_ptr<TextSearchJumpTable> pJumpTable;
73 std::unique_ptr<TextSearchJumpTable> pJumpTable2;
74 bool bIsForwardTab;
75 bool bUsePrimarySrchStr;
76 void MakeForwardTab();
77 void MakeForwardTab2();
78 void MakeBackwardTab();
79 void MakeBackwardTab2();
80 sal_Int32 GetDiff( const sal_Unicode ) const;
81 /// @throws css::uno::RuntimeException
82 css::util::SearchResult SAL_CALL
83 NSrchFrwrd( const OUString& searchStr,
84 sal_Int32 startPos, sal_Int32 endPos );
85 /// @throws css::uno::RuntimeException
86 css::util::SearchResult SAL_CALL
87 NSrchBkwrd( const OUString& searchStr,
88 sal_Int32 startPos, sal_Int32 endPos );
90 // Members and methods for the regular expression search
91 std::unique_ptr<icu::RegexMatcher> pRegexMatcher;
92 /// @throws css::uno::RuntimeException
93 css::util::SearchResult SAL_CALL
94 RESrchFrwrd( const OUString& searchStr,
95 sal_Int32 startPos, sal_Int32 endPos );
96 /// @throws css::uno::RuntimeException
97 css::util::SearchResult SAL_CALL
98 RESrchBkwrd( const OUString& searchStr,
99 sal_Int32 startPos, sal_Int32 endPos );
100 void RESrchPrepare( const css::util::SearchOptions2&);
102 // Members and methods for the "Weight Levenshtein-Distance" search
103 int nLimit;
104 std::unique_ptr<WLevDistance> pWLD;
105 css::uno::Reference < css::i18n::XBreakIterator > xBreak;
106 /// @throws css::uno::RuntimeException
107 css::util::SearchResult SAL_CALL
108 ApproxSrchFrwrd( const OUString& searchStr,
109 sal_Int32 startPos, sal_Int32 endPos );
110 /// @throws css::uno::RuntimeException
111 css::util::SearchResult SAL_CALL
112 ApproxSrchBkwrd( const OUString& searchStr,
113 sal_Int32 startPos, sal_Int32 endPos );
115 // Members and methods for the wildcard search
116 OUString maWildcardReversePattern;
117 OUString maWildcardReversePattern2;
118 sal_uInt32 mcWildcardEscapeChar;
119 bool mbWildcardAllowSubstring;
120 /// @throws css::uno::RuntimeException
121 css::util::SearchResult SAL_CALL
122 WildcardSrchFrwrd( const OUString& searchStr,
123 sal_Int32 startPos, sal_Int32 endPos );
124 /// @throws css::uno::RuntimeException
125 css::util::SearchResult SAL_CALL
126 WildcardSrchBkwrd( const OUString& searchStr,
127 sal_Int32 startPos, sal_Int32 endPos );
129 bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
131 bool checkCTLStart, checkCTLEnd;
132 /// @throws css::uno::RuntimeException
133 bool isCellStart(const OUString& searchStr, sal_Int32 nPos);
135 public:
136 explicit TextSearch(
137 const css::uno::Reference < css::uno::XComponentContext >& rxContext );
139 virtual ~TextSearch() override;
141 // XTextSearch
142 virtual void SAL_CALL
143 setOptions( const css::util::SearchOptions& options ) override;
144 virtual css::util::SearchResult SAL_CALL
145 searchForward( const OUString& searchStr,
146 sal_Int32 startPos, sal_Int32 endPos ) override;
147 virtual css::util::SearchResult SAL_CALL
148 searchBackward( const OUString& searchStr,
149 sal_Int32 startPos, sal_Int32 endPos ) override;
151 // XTextSearch2
152 virtual void SAL_CALL
153 setOptions2( const css::util::SearchOptions2& options ) override;
155 //XServiceInfo
156 virtual OUString SAL_CALL getImplementationName() override;
157 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
158 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
161 #endif
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */