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
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
35namespace com::sun::star::i18n { class XBreakIterator; }
36namespace com::sun::star::i18n { class XCharacterClassification; }
37namespace com::sun::star::i18n { class XExtendedTransliteration; }
38namespace com::sun::star::uno { class XComponentContext; }
39
40
41class WLevDistance;
42typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
43
44class 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
106 std::unique_ptr<WLevDistance> pWLD;
107 css::uno::Reference < css::i18n::XBreakIterator > xBreak;
110 ApproxSrchFrwrd( const OUString& searchStr,
111 sal_Int32 startPos, sal_Int32 endPos );
114 ApproxSrchBkwrd( const OUString& searchStr,
115 sal_Int32 startPos, sal_Int32 endPos );
116
117 // Members and methods for the wildcard search
124 WildcardSrchFrwrd( const OUString& searchStr,
125 sal_Int32 startPos, sal_Int32 endPos );
128 WildcardSrchBkwrd( const OUString& searchStr,
129 sal_Int32 startPos, sal_Int32 endPos );
130
131 bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
132
133public:
134 explicit TextSearch(
135 const css::uno::Reference < css::uno::XComponentContext >& rxContext );
136
137 virtual ~TextSearch() override;
138
139 // XTextSearch
140 virtual void SAL_CALL
141 setOptions( const css::util::SearchOptions& options ) override;
142 virtual css::util::SearchResult SAL_CALL
143 searchForward( const OUString& searchStr,
144 sal_Int32 startPos, sal_Int32 endPos ) override;
145 virtual css::util::SearchResult SAL_CALL
146 searchBackward( const OUString& searchStr,
147 sal_Int32 startPos, sal_Int32 endPos ) override;
148
149 // XTextSearch2
150 virtual void SAL_CALL
151 setOptions2( const css::util::SearchOptions2& options ) override;
152
153 //XServiceInfo
154 virtual OUString SAL_CALL getImplementationName() override;
155 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
156 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
157};
158
159#endif
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: textsearch.hxx:51
virtual css::util::SearchResult SAL_CALL searchForward(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos) override
Definition: textsearch.cxx:301
sal_Int32 startPos
Definition: textsearch.hxx:65
std::unique_ptr< WLevDistance > pWLD
Definition: textsearch.hxx:106
void RESrchPrepare(const css::util::SearchOptions2 &)
Definition: textsearch.cxx:833
FnSrch fnBackward
Definition: textsearch.hxx:68
css::util::SearchResult SAL_CALL RESrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:922
bool bUsePrimarySrchStr
Definition: textsearch.hxx:77
std::unique_ptr< TextSearchJumpTable > pJumpTable
Definition: textsearch.hxx:74
bool bIsForwardTab
Definition: textsearch.hxx:76
OUString maWildcardReversePattern
Definition: textsearch.hxx:118
bool IsDelimiter(const OUString &rStr, sal_Int32 nPos) const
Definition: textsearch.cxx:563
css::util::SearchResult SAL_CALL WildcardSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
OUString maWildcardReversePattern2
Definition: textsearch.hxx:119
css::util::SearchResult SAL_CALL RESrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:976
virtual ~TextSearch() override
Definition: textsearch.cxx:109
css::util::SearchOptions2 aSrchPara
Definition: textsearch.hxx:53
virtual css::util::SearchResult SAL_CALL searchBackward(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos) override
Definition: textsearch.cxx:440
std::unique_ptr< TextSearchJumpTable > pJumpTable2
Definition: textsearch.hxx:75
virtual void SAL_CALL setOptions2(const css::util::SearchOptions2 &options) override
Definition: textsearch.cxx:117
bool bSearchApostrophe
Definition: textsearch.hxx:71
void MakeBackwardTab()
Definition: textsearch.cxx:633
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit2
Definition: textsearch.hxx:60
OUString sSrchStr2
Definition: textsearch.hxx:55
bool mbWildcardAllowSubstring
Definition: textsearch.hxx:121
css::util::SearchResult SAL_CALL NSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:762
sal_uInt32 mcWildcardEscapeChar
Definition: textsearch.hxx:120
virtual OUString SAL_CALL getImplementationName() override
css::util::SearchResult SAL_CALL ApproxSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
sal_Int32 GetDiff(const sal_Unicode) const
Definition: textsearch.cxx:679
void MakeBackwardTab2()
Definition: textsearch.cxx:656
OUString sSrchStr
Definition: textsearch.hxx:54
sal_Int32 sal_Int32 endPos
Definition: textsearch.hxx:65
FnSrch fnForward
Definition: textsearch.hxx:67
css::util::SearchResult SAL_CALL WildcardSrchBkwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
typedef css::util::SearchResult(SAL_CALL TextSearch::*FnSrch)(const OUString &searchStr
void MakeForwardTab()
Definition: textsearch.cxx:582
void MakeForwardTab2()
Definition: textsearch.cxx:608
css::uno::Reference< css::i18n::XExtendedTransliteration > xTranslit
Definition: textsearch.hxx:59
std::mutex m_aMutex
Definition: textsearch.hxx:50
css::util::SearchResult SAL_CALL NSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
Definition: textsearch.cxx:699
virtual void SAL_CALL setOptions(const css::util::SearchOptions &options) override
Definition: textsearch.cxx:258
css::uno::Reference< css::i18n::XCharacterClassification > xCharClass
Definition: textsearch.hxx:57
css::util::SearchResult SAL_CALL ApproxSrchFrwrd(const OUString &searchStr, sal_Int32 startPos, sal_Int32 endPos)
std::unique_ptr< icu::RegexMatcher > pRegexMatcher
Definition: textsearch.hxx:93
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
TextSearch(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
css::uno::Reference< css::i18n::XBreakIterator > xBreak
Definition: textsearch.hxx:107
Weighted Levenshtein Distance (WLD)
Definition: levdis.hxx:134
::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable
Definition: textsearch.hxx:41
unsigned char sal_Bool
sal_uInt16 sal_Unicode