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