1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef INCLUDED_I18NPOOL_TEXTSEARCH_HXX 29*cdf0e10cSrcweir #define INCLUDED_I18NPOOL_TEXTSEARCH_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/util/XTextSearch.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp> 34*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> // helper for implementations 35*cdf0e10cSrcweir #include <com/sun/star/i18n/XExtendedTransliteration.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/i18n/XCharacterClassification.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <map> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir class Regexpr; 42*cdf0e10cSrcweir class WLevDistance; 43*cdf0e10cSrcweir typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // ---------------------------------------------------- 46*cdf0e10cSrcweir // class SearchClass 47*cdf0e10cSrcweir // ---------------------------------------------------- 48*cdf0e10cSrcweir class TextSearch: public cppu::WeakImplHelper2 49*cdf0e10cSrcweir < 50*cdf0e10cSrcweir ::com::sun::star::util::XTextSearch, 51*cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo 52*cdf0e10cSrcweir > 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xMSF; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir ::com::sun::star::util::SearchOptions aSrchPara; 57*cdf0e10cSrcweir ::rtl::OUString sSrchStr; 58*cdf0e10cSrcweir ::rtl::OUString sSrchStr2; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir mutable com::sun::star::uno::Reference< 61*cdf0e10cSrcweir com::sun::star::i18n::XCharacterClassification > xCharClass; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir com::sun::star::uno::Reference< 64*cdf0e10cSrcweir com::sun::star::i18n::XExtendedTransliteration > xTranslit; 65*cdf0e10cSrcweir com::sun::star::uno::Reference< 66*cdf0e10cSrcweir com::sun::star::i18n::XExtendedTransliteration > xTranslit2; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // define a function pointer for the different search nethods 69*cdf0e10cSrcweir typedef ::com::sun::star::util::SearchResult 70*cdf0e10cSrcweir (SAL_CALL TextSearch:: *FnSrch)( const ::rtl::OUString& searchStr, 71*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir FnSrch fnForward; 74*cdf0e10cSrcweir FnSrch fnBackward; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // Members and methods for the normal (Boyer-Moore) search 77*cdf0e10cSrcweir TextSearchJumpTable* pJumpTable; 78*cdf0e10cSrcweir TextSearchJumpTable* pJumpTable2; 79*cdf0e10cSrcweir bool bIsForwardTab; 80*cdf0e10cSrcweir bool bUsePrimarySrchStr; 81*cdf0e10cSrcweir void MakeForwardTab(); 82*cdf0e10cSrcweir void MakeForwardTab2(); 83*cdf0e10cSrcweir void MakeBackwardTab(); 84*cdf0e10cSrcweir void MakeBackwardTab2(); 85*cdf0e10cSrcweir sal_Int32 GetDiff( const sal_Unicode ) const; 86*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 87*cdf0e10cSrcweir NSrchFrwrd( const ::rtl::OUString& searchStr, 88*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 89*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 90*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 91*cdf0e10cSrcweir NSrchBkwrd( const ::rtl::OUString& searchStr, 92*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 93*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // Members and methods for the regular expression search 96*cdf0e10cSrcweir Regexpr* pRegExp; 97*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 98*cdf0e10cSrcweir RESrchFrwrd( const ::rtl::OUString& searchStr, 99*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 100*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 101*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 102*cdf0e10cSrcweir RESrchBkwrd( const ::rtl::OUString& searchStr, 103*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 104*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // Members and methods for the "Weight Levenshtein-Distance" search 107*cdf0e10cSrcweir int nLimit; 108*cdf0e10cSrcweir WLevDistance* pWLD; 109*cdf0e10cSrcweir com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > xBreak; 110*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 111*cdf0e10cSrcweir ApproxSrchFrwrd( const ::rtl::OUString& searchStr, 112*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 113*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 114*cdf0e10cSrcweir ::com::sun::star::util::SearchResult SAL_CALL 115*cdf0e10cSrcweir ApproxSrchBkwrd( const ::rtl::OUString& searchStr, 116*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 117*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir bool IsDelimiter( const ::rtl::OUString& rStr, sal_Int32 nPos ) const; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir sal_Bool checkCTLStart, checkCTLEnd; 122*cdf0e10cSrcweir sal_Bool SAL_CALL isCellStart(const ::rtl::OUString& searchStr, sal_Int32 nPos) 123*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir public: 126*cdf0e10cSrcweir TextSearch( 127*cdf0e10cSrcweir const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& rxMSF ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir virtual ~TextSearch(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // Methods 132*cdf0e10cSrcweir virtual void SAL_CALL 133*cdf0e10cSrcweir setOptions( const ::com::sun::star::util::SearchOptions& options ) 134*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 135*cdf0e10cSrcweir virtual ::com::sun::star::util::SearchResult SAL_CALL 136*cdf0e10cSrcweir searchForward( const ::rtl::OUString& searchStr, 137*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 138*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 139*cdf0e10cSrcweir virtual ::com::sun::star::util::SearchResult SAL_CALL 140*cdf0e10cSrcweir searchBackward( const ::rtl::OUString& searchStr, 141*cdf0e10cSrcweir sal_Int32 startPos, sal_Int32 endPos ) 142*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir //XServiceInfo 145*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName(void) 146*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ); 147*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) 148*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ); 149*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) 150*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ); 151*cdf0e10cSrcweir }; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir #endif 155