Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / search / textsearch.hxx
blob8bd86a5866826edf4a6e9b3f87fdf393204ed231
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_TEXTSEARCH_HXX
21 #define INCLUDED_I18NPOOL_TEXTSEARCH_HXX
23 #include <cppuhelper/implbase2.hxx>
24 #include <com/sun/star/util/XTextSearch.hpp>
25 #include <com/sun/star/i18n/XBreakIterator.hpp>
26 #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
27 #include <com/sun/star/i18n/XCharacterClassification.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <map>
33 #include <unicode/regex.h>
34 using namespace U_ICU_NAMESPACE;
35 typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
37 class WLevDistance;
38 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
40 class TextSearch: public cppu::WeakImplHelper2
42 ::com::sun::star::util::XTextSearch,
43 ::com::sun::star::lang::XServiceInfo
46 ::com::sun::star::uno::Reference < ::com::sun::star::uno::XComponentContext > m_xContext;
48 ::com::sun::star::util::SearchOptions aSrchPara;
49 ::rtl::OUString sSrchStr;
50 ::rtl::OUString sSrchStr2;
52 mutable com::sun::star::uno::Reference<
53 com::sun::star::i18n::XCharacterClassification > xCharClass;
55 com::sun::star::uno::Reference<
56 com::sun::star::i18n::XExtendedTransliteration > xTranslit;
57 com::sun::star::uno::Reference<
58 com::sun::star::i18n::XExtendedTransliteration > xTranslit2;
60 // define a function pointer for the different search nethods
61 typedef ::com::sun::star::util::SearchResult
62 (SAL_CALL TextSearch:: *FnSrch)( const ::rtl::OUString& searchStr,
63 sal_Int32 startPos, sal_Int32 endPos );
65 FnSrch fnForward;
66 FnSrch fnBackward;
68 // Members and methods for the normal (Boyer-Moore) search
69 TextSearchJumpTable* pJumpTable;
70 TextSearchJumpTable* pJumpTable2;
71 bool bIsForwardTab;
72 bool bUsePrimarySrchStr;
73 void MakeForwardTab();
74 void MakeForwardTab2();
75 void MakeBackwardTab();
76 void MakeBackwardTab2();
77 sal_Int32 GetDiff( const sal_Unicode ) const;
78 ::com::sun::star::util::SearchResult SAL_CALL
79 NSrchFrwrd( const ::rtl::OUString& searchStr,
80 sal_Int32 startPos, sal_Int32 endPos )
81 throw(::com::sun::star::uno::RuntimeException);
82 ::com::sun::star::util::SearchResult SAL_CALL
83 NSrchBkwrd( const ::rtl::OUString& searchStr,
84 sal_Int32 startPos, sal_Int32 endPos )
85 throw(::com::sun::star::uno::RuntimeException);
87 // Members and methods for the regular expression search
88 RegexMatcher* pRegexMatcher;
89 ::com::sun::star::util::SearchResult SAL_CALL
90 RESrchFrwrd( const ::rtl::OUString& searchStr,
91 sal_Int32 startPos, sal_Int32 endPos )
92 throw(::com::sun::star::uno::RuntimeException);
93 ::com::sun::star::util::SearchResult SAL_CALL
94 RESrchBkwrd( const ::rtl::OUString& searchStr,
95 sal_Int32 startPos, sal_Int32 endPos )
96 throw(::com::sun::star::uno::RuntimeException);
97 void RESrchPrepare( const ::com::sun::star::util::SearchOptions&);
99 // Members and methods for the "Weight Levenshtein-Distance" search
100 int nLimit;
101 WLevDistance* pWLD;
102 com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > xBreak;
103 ::com::sun::star::util::SearchResult SAL_CALL
104 ApproxSrchFrwrd( const ::rtl::OUString& searchStr,
105 sal_Int32 startPos, sal_Int32 endPos )
106 throw(::com::sun::star::uno::RuntimeException);
107 ::com::sun::star::util::SearchResult SAL_CALL
108 ApproxSrchBkwrd( const ::rtl::OUString& searchStr,
109 sal_Int32 startPos, sal_Int32 endPos )
110 throw(::com::sun::star::uno::RuntimeException);
112 bool IsDelimiter( const ::rtl::OUString& rStr, sal_Int32 nPos ) const;
114 sal_Bool checkCTLStart, checkCTLEnd;
115 sal_Bool SAL_CALL isCellStart(const ::rtl::OUString& searchStr, sal_Int32 nPos)
116 throw(::com::sun::star::uno::RuntimeException);
118 public:
119 TextSearch(
120 const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XComponentContext >& rxContext );
122 virtual ~TextSearch();
124 // Methods
125 virtual void SAL_CALL
126 setOptions( const ::com::sun::star::util::SearchOptions& options )
127 throw(::com::sun::star::uno::RuntimeException);
128 virtual ::com::sun::star::util::SearchResult SAL_CALL
129 searchForward( const ::rtl::OUString& searchStr,
130 sal_Int32 startPos, sal_Int32 endPos )
131 throw(::com::sun::star::uno::RuntimeException);
132 virtual ::com::sun::star::util::SearchResult SAL_CALL
133 searchBackward( const ::rtl::OUString& searchStr,
134 sal_Int32 startPos, sal_Int32 endPos )
135 throw(::com::sun::star::uno::RuntimeException);
137 //XServiceInfo
138 virtual rtl::OUString SAL_CALL getImplementationName(void)
139 throw( ::com::sun::star::uno::RuntimeException );
140 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
141 throw( ::com::sun::star::uno::RuntimeException );
142 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void)
143 throw( ::com::sun::star::uno::RuntimeException );
146 #endif
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */