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 throw(::com::sun::star::uno::RuntimeException); 89 ::com::sun::star::util::SearchResult SAL_CALL 90 NSrchBkwrd( const ::rtl::OUString& searchStr, 91 sal_Int32 startPos, sal_Int32 endPos ) 92 throw(::com::sun::star::uno::RuntimeException); 93 94 // Members and methods for the regular expression search 95 RegexMatcher* pRegexMatcher; 96 ::com::sun::star::util::SearchResult SAL_CALL 97 RESrchFrwrd( const ::rtl::OUString& searchStr, 98 sal_Int32 startPos, sal_Int32 endPos ) 99 throw(::com::sun::star::uno::RuntimeException); 100 ::com::sun::star::util::SearchResult SAL_CALL 101 RESrchBkwrd( const ::rtl::OUString& searchStr, 102 sal_Int32 startPos, sal_Int32 endPos ) 103 throw(::com::sun::star::uno::RuntimeException); 104 void RESrchPrepare( const ::com::sun::star::util::SearchOptions&); 105 106 // Members and methods for the "Weight Levenshtein-Distance" search 107 int nLimit; 108 WLevDistance* pWLD; 109 com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > xBreak; 110 ::com::sun::star::util::SearchResult SAL_CALL 111 ApproxSrchFrwrd( const ::rtl::OUString& searchStr, 112 sal_Int32 startPos, sal_Int32 endPos ) 113 throw(::com::sun::star::uno::RuntimeException); 114 ::com::sun::star::util::SearchResult SAL_CALL 115 ApproxSrchBkwrd( const ::rtl::OUString& searchStr, 116 sal_Int32 startPos, sal_Int32 endPos ) 117 throw(::com::sun::star::uno::RuntimeException); 118 119 bool IsDelimiter( const ::rtl::OUString& rStr, sal_Int32 nPos ) const; 120 121 sal_Bool checkCTLStart, checkCTLEnd; 122 sal_Bool SAL_CALL isCellStart(const ::rtl::OUString& searchStr, sal_Int32 nPos) 123 throw(::com::sun::star::uno::RuntimeException); 124 125 public: 126 TextSearch( 127 const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& rxMSF ); 128 129 virtual ~TextSearch(); 130 131 // Methods 132 virtual void SAL_CALL 133 setOptions( const ::com::sun::star::util::SearchOptions& options ) 134 throw(::com::sun::star::uno::RuntimeException); 135 virtual ::com::sun::star::util::SearchResult SAL_CALL 136 searchForward( const ::rtl::OUString& searchStr, 137 sal_Int32 startPos, sal_Int32 endPos ) 138 throw(::com::sun::star::uno::RuntimeException); 139 virtual ::com::sun::star::util::SearchResult SAL_CALL 140 searchBackward( const ::rtl::OUString& searchStr, 141 sal_Int32 startPos, sal_Int32 endPos ) 142 throw(::com::sun::star::uno::RuntimeException); 143 144 //XServiceInfo 145 virtual rtl::OUString SAL_CALL getImplementationName(void) 146 throw( ::com::sun::star::uno::RuntimeException ); 147 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) 148 throw( ::com::sun::star::uno::RuntimeException ); 149 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) 150 throw( ::com::sun::star::uno::RuntimeException ); 151 }; 152 153 #endif 154