1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_I18NPOOL_TEXTSEARCH_HXX 29 #define INCLUDED_I18NPOOL_TEXTSEARCH_HXX 30 31 32 #include <com/sun/star/util/XTextSearch.hpp> 33 #include <com/sun/star/i18n/XBreakIterator.hpp> 34 #include <cppuhelper/implbase2.hxx> // helper for implementations 35 #include <com/sun/star/i18n/XExtendedTransliteration.hpp> 36 #include <com/sun/star/i18n/XCharacterClassification.hpp> 37 #include <com/sun/star/lang/XServiceInfo.hpp> 38 39 #include <map> 40 41 class Regexpr; 42 class WLevDistance; 43 typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable; 44 45 // ---------------------------------------------------- 46 // class SearchClass 47 // ---------------------------------------------------- 48 class TextSearch: public cppu::WeakImplHelper2 49 < 50 ::com::sun::star::util::XTextSearch, 51 ::com::sun::star::lang::XServiceInfo 52 > 53 { 54 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xMSF; 55 56 ::com::sun::star::util::SearchOptions aSrchPara; 57 ::rtl::OUString sSrchStr; 58 ::rtl::OUString sSrchStr2; 59 60 mutable com::sun::star::uno::Reference< 61 com::sun::star::i18n::XCharacterClassification > xCharClass; 62 63 com::sun::star::uno::Reference< 64 com::sun::star::i18n::XExtendedTransliteration > xTranslit; 65 com::sun::star::uno::Reference< 66 com::sun::star::i18n::XExtendedTransliteration > xTranslit2; 67 68 // define a function pointer for the different search nethods 69 typedef ::com::sun::star::util::SearchResult 70 (SAL_CALL TextSearch:: *FnSrch)( const ::rtl::OUString& searchStr, 71 sal_Int32 startPos, sal_Int32 endPos ); 72 73 FnSrch fnForward; 74 FnSrch fnBackward; 75 76 // Members and methods for the normal (Boyer-Moore) search 77 TextSearchJumpTable* pJumpTable; 78 TextSearchJumpTable* pJumpTable2; 79 bool bIsForwardTab; 80 bool bUsePrimarySrchStr; 81 void MakeForwardTab(); 82 void MakeForwardTab2(); 83 void MakeBackwardTab(); 84 void MakeBackwardTab2(); 85 sal_Int32 GetDiff( const sal_Unicode ) const; 86 ::com::sun::star::util::SearchResult SAL_CALL 87 NSrchFrwrd( const ::rtl::OUString& searchStr, 88 sal_Int32 startPos, sal_Int32 endPos ) 89 throw(::com::sun::star::uno::RuntimeException); 90 ::com::sun::star::util::SearchResult SAL_CALL 91 NSrchBkwrd( const ::rtl::OUString& searchStr, 92 sal_Int32 startPos, sal_Int32 endPos ) 93 throw(::com::sun::star::uno::RuntimeException); 94 95 // Members and methods for the regular expression search 96 Regexpr* pRegExp; 97 ::com::sun::star::util::SearchResult SAL_CALL 98 RESrchFrwrd( const ::rtl::OUString& searchStr, 99 sal_Int32 startPos, sal_Int32 endPos ) 100 throw(::com::sun::star::uno::RuntimeException); 101 ::com::sun::star::util::SearchResult SAL_CALL 102 RESrchBkwrd( const ::rtl::OUString& searchStr, 103 sal_Int32 startPos, sal_Int32 endPos ) 104 throw(::com::sun::star::uno::RuntimeException); 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 154 #endif 155