bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / search / textsearch.hxx
blobacc49a00ee5a30e783c0a9464e5c82de4dc89042
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 using namespace U_ICU_NAMESPACE;
41 typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
43 class WLevDistance;
44 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
46 class TextSearch: public cppu::WeakImplHelper
48 css::util::XTextSearch2,
49 css::lang::XServiceInfo
52 osl::Mutex m_aMutex;
53 css::uno::Reference < css::uno::XComponentContext > m_xContext;
55 css::util::SearchOptions2 aSrchPara;
56 OUString sSrchStr;
57 OUString sSrchStr2;
59 mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
61 css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit;
62 css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2;
64 // define a function pointer for the different search methods
65 typedef css::util::SearchResult
66 (SAL_CALL TextSearch:: *FnSrch)( const OUString& searchStr,
67 sal_Int32 startPos, sal_Int32 endPos );
69 FnSrch fnForward;
70 FnSrch fnBackward;
72 // Members and methods for the normal (Boyer-Moore) search
73 std::unique_ptr<TextSearchJumpTable> pJumpTable;
74 std::unique_ptr<TextSearchJumpTable> pJumpTable2;
75 bool bIsForwardTab;
76 bool bUsePrimarySrchStr;
77 void MakeForwardTab();
78 void MakeForwardTab2();
79 void MakeBackwardTab();
80 void MakeBackwardTab2();
81 sal_Int32 GetDiff( const sal_Unicode ) const;
82 /// @throws css::uno::RuntimeException
83 css::util::SearchResult SAL_CALL
84 NSrchFrwrd( const OUString& searchStr,
85 sal_Int32 startPos, sal_Int32 endPos );
86 /// @throws css::uno::RuntimeException
87 css::util::SearchResult SAL_CALL
88 NSrchBkwrd( const OUString& searchStr,
89 sal_Int32 startPos, sal_Int32 endPos );
91 // Members and methods for the regular expression search
92 std::unique_ptr<RegexMatcher> pRegexMatcher;
93 /// @throws css::uno::RuntimeException
94 css::util::SearchResult SAL_CALL
95 RESrchFrwrd( const OUString& searchStr,
96 sal_Int32 startPos, sal_Int32 endPos );
97 /// @throws css::uno::RuntimeException
98 css::util::SearchResult SAL_CALL
99 RESrchBkwrd( const OUString& searchStr,
100 sal_Int32 startPos, sal_Int32 endPos );
101 void RESrchPrepare( const css::util::SearchOptions2&);
103 // Members and methods for the "Weight Levenshtein-Distance" search
104 int nLimit;
105 std::unique_ptr<WLevDistance> pWLD;
106 css::uno::Reference < css::i18n::XBreakIterator > xBreak;
107 /// @throws css::uno::RuntimeException
108 css::util::SearchResult SAL_CALL
109 ApproxSrchFrwrd( const OUString& searchStr,
110 sal_Int32 startPos, sal_Int32 endPos );
111 /// @throws css::uno::RuntimeException
112 css::util::SearchResult SAL_CALL
113 ApproxSrchBkwrd( const OUString& searchStr,
114 sal_Int32 startPos, sal_Int32 endPos );
116 // Members and methods for the wildcard search
117 OUString maWildcardReversePattern;
118 OUString maWildcardReversePattern2;
119 sal_uInt32 mcWildcardEscapeChar;
120 bool mbWildcardAllowSubstring;
121 /// @throws css::uno::RuntimeException
122 css::util::SearchResult SAL_CALL
123 WildcardSrchFrwrd( const OUString& searchStr,
124 sal_Int32 startPos, sal_Int32 endPos );
125 /// @throws css::uno::RuntimeException
126 css::util::SearchResult SAL_CALL
127 WildcardSrchBkwrd( const OUString& searchStr,
128 sal_Int32 startPos, sal_Int32 endPos );
130 bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
132 bool checkCTLStart, checkCTLEnd;
133 /// @throws css::uno::RuntimeException
134 bool isCellStart(const OUString& searchStr, sal_Int32 nPos);
136 public:
137 explicit TextSearch(
138 const css::uno::Reference < css::uno::XComponentContext >& rxContext );
140 virtual ~TextSearch() override;
142 // XTextSearch
143 virtual void SAL_CALL
144 setOptions( const css::util::SearchOptions& options ) override;
145 virtual css::util::SearchResult SAL_CALL
146 searchForward( const OUString& searchStr,
147 sal_Int32 startPos, sal_Int32 endPos ) override;
148 virtual css::util::SearchResult SAL_CALL
149 searchBackward( const OUString& searchStr,
150 sal_Int32 startPos, sal_Int32 endPos ) override;
152 // XTextSearch2
153 virtual void SAL_CALL
154 setOptions2( const css::util::SearchOptions2& options ) override;
156 //XServiceInfo
157 virtual OUString SAL_CALL getImplementationName() override;
158 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
159 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
162 #endif
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */