LCOV - code coverage report
Current view: top level - libreoffice/unotools/inc/unotools - textsearch.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 11 54.5 %
Date: 2012-12-17 Functions: 6 11 54.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include "unotools/unotoolsdllapi.h"
      20             : 
      21             : #ifndef _UNOTOOLS_TEXTSEARCH_HXX
      22             : #define _UNOTOOLS_TEXTSEARCH_HXX
      23             : #include <i18npool/lang.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <tools/string.hxx>
      26             : #include <com/sun/star/uno/Reference.h>
      27             : #include <com/sun/star/lang/Locale.hpp>
      28             : #include <com/sun/star/util/XTextSearch.hpp>
      29             : #include <com/sun/star/util/SearchOptions.hpp>
      30             : 
      31             : class CharClass;
      32             : 
      33             : namespace com {
      34             :     namespace sun {
      35             :         namespace star {
      36             :             namespace util {
      37             :                 struct SearchResult;
      38             :             }
      39             :         }
      40             :     }
      41             : }
      42             : 
      43             : // ............................................................................
      44             : namespace utl
      45             : {
      46             : // ............................................................................
      47             : 
      48             : // Utility class for searching
      49             : class UNOTOOLS_DLLPUBLIC SearchParam
      50             : {
      51             : public:
      52             :     enum SearchType{ SRCH_NORMAL, SRCH_REGEXP, SRCH_LEVDIST };
      53             : 
      54             : private:
      55             :     String sSrchStr;            // the search string
      56             :     String sReplaceStr;         // the replace string
      57             : 
      58             :     SearchType m_eSrchType;       // search normal/regular/LevDist
      59             : 
      60             :     int m_bWordOnly   : 1;        // used by normal search
      61             :     int m_bSrchInSel  : 1;        // search only in the selection
      62             :     int m_bCaseSense  : 1;        //
      63             : 
      64             :     // values for the "weight Levenshtein-Distance"
      65             :     int bLEV_Relaxed : 1;
      66             :     int nLEV_OtherX;
      67             :     int nLEV_ShorterY;
      68             :     int nLEV_LongerZ;
      69             : 
      70             :     // asian flags - used for the transliteration
      71             :     long nTransliterationFlags;
      72             : 
      73             : public:
      74             :     SearchParam( const rtl::OUString &rText,
      75             :                     SearchType eSrchType = SearchParam::SRCH_NORMAL,
      76             :                     sal_Bool bCaseSensitive = sal_True,
      77             :                     sal_Bool bWordOnly = sal_False,
      78             :                     sal_Bool bSearchInSelection = sal_False );
      79             : 
      80             :     SearchParam( const SearchParam& );
      81             : 
      82             :     ~SearchParam();
      83             : 
      84           2 :     const String&   GetSrchStr() const          { return sSrchStr; }
      85           2 :     const String&   GetReplaceStr() const       { return sReplaceStr; }
      86           2 :     SearchType      GetSrchType() const         { return m_eSrchType; }
      87             : 
      88           2 :     int             IsCaseSensitive() const     { return m_bCaseSense; }
      89           2 :     int             IsSrchInSelection() const   { return m_bSrchInSel; }
      90           0 :     int             IsSrchWordOnly() const      { return m_bWordOnly; }
      91             : 
      92             : 
      93             :     void SetSrchStr( const String& rStr )       { sSrchStr = rStr; }
      94             :     void SetReplaceStr( const String& rStr )    { sReplaceStr = rStr; }
      95             :     void SetSrchType( SearchType eType )        { m_eSrchType = eType; }
      96             : 
      97             :     void SetCaseSensitive( int bFlag )          { m_bCaseSense = bFlag; }
      98             :     void SetSrchInSelection( int bFlag )        { m_bSrchInSel = bFlag; }
      99             :     void SetSrchWordOnly( int bFlag )           { m_bWordOnly = bFlag; }
     100             : 
     101           0 :     int             IsSrchRelaxed() const       { return bLEV_Relaxed; }
     102           0 :     int             GetLEVOther() const         { return nLEV_OtherX; }
     103           0 :     int             GetLEVShorter() const       { return nLEV_ShorterY; }
     104           0 :     int             GetLEVLonger() const        { return nLEV_LongerZ; }
     105             : 
     106             :     void SetSrchRelaxed( int bFlag )            { bLEV_Relaxed = bFlag; }
     107             :     void SetLEVOther( int nValue )              { nLEV_OtherX = nValue; }
     108             :     void SetLEVShorter( int nValue )            { nLEV_ShorterY = nValue; }
     109             :     void SetLEVLonger( int nValue )             { nLEV_LongerZ = nValue; }
     110             : 
     111           2 :     long GetTransliterationFlags() const        { return nTransliterationFlags; }
     112             :     void SetTransliterationFlags( long nValue ) { nTransliterationFlags = nValue; }
     113             : };
     114             : 
     115             : //  Utility class for searching a substring in a string.
     116             : //  The following metrics are supported
     117             : //      - ordinary text (Bayer/Moore)
     118             : //      - regular expressions
     119             : //      - weighted Levenshtein distance
     120             : //
     121             : //  This class allows forward and backward searching!
     122             : 
     123             : class UNOTOOLS_DLLPUBLIC TextSearch
     124             : {
     125             :     static ::com::sun::star::uno::Reference< ::com::sun::star::util::XTextSearch >
     126             :         getXTextSearch( const ::com::sun::star::util::SearchOptions& rPara );
     127             : 
     128             :     com::sun::star::uno::Reference < com::sun::star::util::XTextSearch >
     129             :             xTextSearch;
     130             : 
     131             :     void Init( const SearchParam & rParam,
     132             :                const ::com::sun::star::lang::Locale& rLocale );
     133             : 
     134             : public:
     135             :     // rText is the string being searched for
     136             :     // this first two CTORs are deprecated!
     137             :     TextSearch( const SearchParam & rPara, LanguageType nLanguage );
     138             :     TextSearch( const SearchParam & rPara, const CharClass& rCClass );
     139             : 
     140             :     TextSearch( const ::com::sun::star::util::SearchOptions& rPara );
     141             :     ~TextSearch();
     142             : 
     143             :     /* search in the (selected) text the search string:
     144             :         rScrTxt - the text, in in which we search
     145             :         pStart  - start position for the search
     146             :         pEnde   - end position for the search
     147             : 
     148             :         RETURN values   ==  sal_True: something is found
     149             :                         - pStart start pos of the found text,
     150             :                         - pStart end pos of the found text,
     151             :                         - pSrchResult - the search result with all found
     152             :                              positions. Is only filled with more positions
     153             :                              if the regular expression handles groups.
     154             : 
     155             :                         == sal_False: nothing found, pStart,pEnde unchanged.
     156             : 
     157             :         Definitions: start pos always inclusive, end pos always exclusive!
     158             :                      The position must always in the right direction!
     159             :                     search forward: start <= end
     160             :                     search backward: end <= start
     161             :     */
     162             :     int SearchFrwrd( const String &rStr,
     163             :                     xub_StrLen* pStart, xub_StrLen* pEnde,
     164             :                     ::com::sun::star::util::SearchResult* pSrchResult = 0 );
     165             :     sal_Bool SearchForward( const ::rtl::OUString &rStr,
     166             :                     sal_Int32* pStart, sal_Int32* pEnd,
     167             :                     ::com::sun::star::util::SearchResult* pRes = 0 );
     168             :     int SearchBkwrd( const String &rStr,
     169             :                     xub_StrLen* pStart, xub_StrLen* pEnde,
     170             :                     ::com::sun::star::util::SearchResult* pSrchResult = 0 );
     171             : 
     172             :     void SetLocale( const ::com::sun::star::util::SearchOptions& rOpt,
     173             :                     const ::com::sun::star::lang::Locale& rLocale );
     174             : 
     175             :     /* replace back references in the replace string by the sub expressions from the search result */
     176             :     void ReplaceBackReferences( String& rReplaceStr, const String &rStr, const ::com::sun::star::util::SearchResult& rResult );
     177             : 
     178             : };
     179             : 
     180             : // ............................................................................
     181             : }   // namespace utl
     182             : // ............................................................................
     183             : 
     184             : #endif
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10