1f7bd9df4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f7bd9df4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f7bd9df4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f7bd9df4SAndrew Rist  * distributed with this work for additional information
6f7bd9df4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f7bd9df4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f7bd9df4SAndrew Rist  * "License"); you may not use this file except in compliance
9f7bd9df4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f7bd9df4SAndrew Rist  *
11f7bd9df4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f7bd9df4SAndrew Rist  *
13f7bd9df4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f7bd9df4SAndrew Rist  * software distributed under the License is distributed on an
15f7bd9df4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f7bd9df4SAndrew Rist  * KIND, either express or implied.  See the License for the
17f7bd9df4SAndrew Rist  * specific language governing permissions and limitations
18f7bd9df4SAndrew Rist  * under the License.
19f7bd9df4SAndrew Rist  *
20f7bd9df4SAndrew Rist  *************************************************************/
21f7bd9df4SAndrew Rist 
22f7bd9df4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_I18NPOOL_TEXTSEARCH_HXX
25cdf0e10cSrcweir #define INCLUDED_I18NPOOL_TEXTSEARCH_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/util/XTextSearch.hpp>
29cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
30cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>		// helper for implementations
31cdf0e10cSrcweir #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
32cdf0e10cSrcweir #include <com/sun/star/i18n/XCharacterClassification.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <map>
36cdf0e10cSrcweir 
37cc450e3aSHerbert Dürr #include <unicode/regex.h>
38cc450e3aSHerbert Dürr using namespace U_ICU_NAMESPACE;
39cc450e3aSHerbert Dürr typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
40cc450e3aSHerbert Dürr 
41cdf0e10cSrcweir class WLevDistance;
42cdf0e10cSrcweir typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //	----------------------------------------------------
45cc450e3aSHerbert Dürr //	class TextSearch
46cdf0e10cSrcweir //	----------------------------------------------------
47cdf0e10cSrcweir class TextSearch: public cppu::WeakImplHelper2
48cdf0e10cSrcweir <
49cdf0e10cSrcweir 	::com::sun::star::util::XTextSearch,
50cdf0e10cSrcweir 	::com::sun::star::lang::XServiceInfo
51cdf0e10cSrcweir >
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xMSF;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	::com::sun::star::util::SearchOptions aSrchPara;
56cdf0e10cSrcweir 	::rtl::OUString sSrchStr;
57cdf0e10cSrcweir 	::rtl::OUString sSrchStr2;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     mutable com::sun::star::uno::Reference<
60cdf0e10cSrcweir         com::sun::star::i18n::XCharacterClassification > xCharClass;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     com::sun::star::uno::Reference<
63cdf0e10cSrcweir         com::sun::star::i18n::XExtendedTransliteration > xTranslit;
64cdf0e10cSrcweir     com::sun::star::uno::Reference<
65cdf0e10cSrcweir         com::sun::star::i18n::XExtendedTransliteration > xTranslit2;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	// define a function pointer for the different search nethods
68cdf0e10cSrcweir     typedef ::com::sun::star::util::SearchResult
69cdf0e10cSrcweir 		(SAL_CALL TextSearch:: *FnSrch)( const ::rtl::OUString& searchStr,
70cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	FnSrch fnForward;
73cdf0e10cSrcweir 	FnSrch fnBackward;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	// Members and methods for the normal (Boyer-Moore) search
76cdf0e10cSrcweir 	TextSearchJumpTable* pJumpTable;
77cdf0e10cSrcweir 	TextSearchJumpTable* pJumpTable2;
78cdf0e10cSrcweir 	bool bIsForwardTab;
79cdf0e10cSrcweir 	bool bUsePrimarySrchStr;
80cdf0e10cSrcweir 	void MakeForwardTab();
81cdf0e10cSrcweir 	void MakeForwardTab2();
82cdf0e10cSrcweir 	void MakeBackwardTab();
83cdf0e10cSrcweir 	void MakeBackwardTab2();
84cdf0e10cSrcweir 	sal_Int32 GetDiff( const sal_Unicode ) const;
85cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
86cdf0e10cSrcweir 		NSrchFrwrd( const ::rtl::OUString& searchStr,
87cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
88cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
89cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
90cdf0e10cSrcweir 		NSrchBkwrd( const ::rtl::OUString& searchStr,
91cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
92cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	// Members and methods for the regular expression search
95cc450e3aSHerbert Dürr 	RegexMatcher* pRegexMatcher;
96cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
97cdf0e10cSrcweir 		RESrchFrwrd( const ::rtl::OUString& searchStr,
98cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
99cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
101cdf0e10cSrcweir 		RESrchBkwrd( const ::rtl::OUString& searchStr,
102cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
103cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
104*7f9f793fSHerbert Dürr 	void RESrchPrepare( const ::com::sun::star::util::SearchOptions&);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	// Members and methods for the "Weight Levenshtein-Distance" search
107cdf0e10cSrcweir 	int nLimit;
108cdf0e10cSrcweir 	WLevDistance* pWLD;
109cdf0e10cSrcweir 	com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > xBreak;
110cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
111cdf0e10cSrcweir 		ApproxSrchFrwrd( const ::rtl::OUString& searchStr,
112cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
113cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir 	::com::sun::star::util::SearchResult SAL_CALL
115cdf0e10cSrcweir 		ApproxSrchBkwrd( const ::rtl::OUString& searchStr,
116cdf0e10cSrcweir 								sal_Int32 startPos, sal_Int32 endPos )
117cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	bool IsDelimiter( const ::rtl::OUString& rStr, sal_Int32 nPos ) const;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	sal_Bool checkCTLStart, checkCTLEnd;
122cdf0e10cSrcweir 	sal_Bool SAL_CALL isCellStart(const ::rtl::OUString& searchStr, sal_Int32 nPos)
123cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir public:
126cdf0e10cSrcweir 	TextSearch(
127cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& rxMSF );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	virtual ~TextSearch();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     // Methods
132cdf0e10cSrcweir     virtual void SAL_CALL
133cdf0e10cSrcweir 		setOptions( const ::com::sun::star::util::SearchOptions& options )
134cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
135cdf0e10cSrcweir     virtual ::com::sun::star::util::SearchResult SAL_CALL
136cdf0e10cSrcweir 		searchForward( const ::rtl::OUString& searchStr,
137cdf0e10cSrcweir 						sal_Int32 startPos, sal_Int32 endPos )
138cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
139cdf0e10cSrcweir     virtual ::com::sun::star::util::SearchResult SAL_CALL
140cdf0e10cSrcweir 		searchBackward( const ::rtl::OUString& searchStr,
141cdf0e10cSrcweir 						sal_Int32 startPos, sal_Int32 endPos )
142cdf0e10cSrcweir 							throw(::com::sun::star::uno::RuntimeException);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     //XServiceInfo
145cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName(void)
146cdf0e10cSrcweir                 throw( ::com::sun::star::uno::RuntimeException );
147cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
148cdf0e10cSrcweir                 throw( ::com::sun::star::uno::RuntimeException );
149cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void)
150cdf0e10cSrcweir                 throw( ::com::sun::star::uno::RuntimeException );
151cdf0e10cSrcweir };
152cdf0e10cSrcweir 
153cdf0e10cSrcweir #endif
154