LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/unotools - textsearch.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 11 54.5 %
Date: 2013-07-09 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 <i18nlangtag/lang.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <com/sun/star/uno/Reference.h>
      26             : #include <com/sun/star/lang/Locale.hpp>
      27             : #include <com/sun/star/util/XTextSearch.hpp>
      28             : #include <com/sun/star/util/SearchOptions.hpp>
      29             : 
      30             : class CharClass;
      31             : 
      32             : namespace com {
      33             :     namespace sun {
      34             :         namespace star {
      35             :             namespace util {
      36             :                 struct SearchResult;
      37             :             }
      38             :         }
      39             :     }
      40             : }
      41             : 
      42             : // ............................................................................
      43             : namespace utl
      44             : {
      45             : // ............................................................................
      46             : 
      47             : // Utility class for searching
      48             : class UNOTOOLS_DLLPUBLIC SearchParam
      49             : {
      50             : public:
      51             :     enum SearchType{ SRCH_NORMAL, SRCH_REGEXP, SRCH_LEVDIST };
      52             : 
      53             : private:
      54             :     OUString sSrchStr;            // the search string
      55             :     OUString sReplaceStr;         // the replace string
      56             : 
      57             :     SearchType m_eSrchType;       // search normal/regular/LevDist
      58             : 
      59             :     int m_bWordOnly   : 1;        // used by normal search
      60             :     int m_bSrchInSel  : 1;        // search only in the selection
      61             :     int m_bCaseSense  : 1;        //
      62             : 
      63             :     // values for the "weight Levenshtein-Distance"
      64             :     int bLEV_Relaxed : 1;
      65             :     int nLEV_OtherX;
      66             :     int nLEV_ShorterY;
      67             :     int nLEV_LongerZ;
      68             : 
      69             :     // asian flags - used for the transliteration
      70             :     long nTransliterationFlags;
      71             : 
      72             : public:
      73             :     SearchParam( const OUString &rText,
      74             :                     SearchType eSrchType = SearchParam::SRCH_NORMAL,
      75             :                     bool bCaseSensitive = true,
      76             :                     bool bWordOnly = false,
      77             :                     bool bSearchInSelection = false );
      78             : 
      79             :     SearchParam( const SearchParam& );
      80             : 
      81             :     ~SearchParam();
      82             : 
      83           6 :     const OUString& GetSrchStr() const          { return sSrchStr; }
      84           6 :     const OUString& GetReplaceStr() const       { return sReplaceStr; }
      85           6 :     SearchType      GetSrchType() const         { return m_eSrchType; }
      86             : 
      87           6 :     int             IsCaseSensitive() const     { return m_bCaseSense; }
      88           6 :     int             IsSrchInSelection() const   { return m_bSrchInSel; }
      89           0 :     int             IsSrchWordOnly() const      { return m_bWordOnly; }
      90             : 
      91             : 
      92             :     void SetSrchStr( const OUString& rStr )     { sSrchStr = rStr; }
      93             :     void SetReplaceStr( const OUString& rStr )  { sReplaceStr = rStr; }
      94             :     void SetSrchType( SearchType eType )        { m_eSrchType = eType; }
      95             : 
      96             :     void SetCaseSensitive( int bFlag )          { m_bCaseSense = bFlag; }
      97             :     void SetSrchInSelection( int bFlag )        { m_bSrchInSel = bFlag; }
      98             :     void SetSrchWordOnly( int bFlag )           { m_bWordOnly = bFlag; }
      99             : 
     100           0 :     int             IsSrchRelaxed() const       { return bLEV_Relaxed; }
     101           0 :     int             GetLEVOther() const         { return nLEV_OtherX; }
     102           0 :     int             GetLEVShorter() const       { return nLEV_ShorterY; }
     103           0 :     int             GetLEVLonger() const        { return nLEV_LongerZ; }
     104             : 
     105             :     void SetSrchRelaxed( int bFlag )            { bLEV_Relaxed = bFlag; }
     106             :     void SetLEVOther( int nValue )              { nLEV_OtherX = nValue; }
     107             :     void SetLEVShorter( int nValue )            { nLEV_ShorterY = nValue; }
     108             :     void SetLEVLonger( int nValue )             { nLEV_LongerZ = nValue; }
     109             : 
     110           6 :     long GetTransliterationFlags() const        { return nTransliterationFlags; }
     111             :     void SetTransliterationFlags( long nValue ) { nTransliterationFlags = nValue; }
     112             : };
     113             : 
     114             : //  Utility class for searching a substring in a string.
     115             : //  The following metrics are supported
     116             : //      - ordinary text (Bayer/Moore)
     117             : //      - regular expressions
     118             : //      - weighted Levenshtein distance
     119             : //
     120             : //  This class allows forward and backward searching!
     121             : 
     122             : class UNOTOOLS_DLLPUBLIC TextSearch
     123             : {
     124             :     static ::com::sun::star::uno::Reference< ::com::sun::star::util::XTextSearch >
     125             :         getXTextSearch( const ::com::sun::star::util::SearchOptions& rPara );
     126             : 
     127             :     com::sun::star::uno::Reference < com::sun::star::util::XTextSearch >
     128             :             xTextSearch;
     129             : 
     130             :     void Init( const SearchParam & rParam,
     131             :                const ::com::sun::star::lang::Locale& rLocale );
     132             : 
     133             : public:
     134             :     // rText is the string being searched for
     135             :     // this first two CTORs are deprecated!
     136             :     TextSearch( const SearchParam & rPara, LanguageType nLanguage );
     137             :     TextSearch( const SearchParam & rPara, const CharClass& rCClass );
     138             : 
     139             :     TextSearch( const ::com::sun::star::util::SearchOptions& rPara );
     140             :     ~TextSearch();
     141             : 
     142             :     /* search in the (selected) text the search string:
     143             :         rScrTxt - the text, in in which we search
     144             :         pStart  - start position for the search
     145             :         pEnde   - end position for the search
     146             : 
     147             :         RETURN values   ==  true: something is found
     148             :                         - pStart start pos of the found text,
     149             :                         - pStart end pos of the found text,
     150             :                         - pSrchResult - the search result with all found
     151             :                              positions. Is only filled with more positions
     152             :                              if the regular expression handles groups.
     153             : 
     154             :                         == false: nothing found, pStart,pEnde unchanged.
     155             : 
     156             :         Definitions: start pos always inclusive, end pos always exclusive!
     157             :                      The position must always in the right direction!
     158             :                     search forward: start <= end
     159             :                     search backward: end <= start
     160             :     */
     161             :     bool SearchForward( const OUString &rStr,
     162             :                         sal_Int32* pStart, sal_Int32* pEnd,
     163             :                         ::com::sun::star::util::SearchResult* pRes = 0 );
     164             :     bool SearchBackward( const OUString &rStr,
     165             :                         sal_Int32* pStart, sal_Int32* pEnd,
     166             :                         ::com::sun::star::util::SearchResult* pRes = 0 );
     167             : 
     168             :     void SetLocale( const ::com::sun::star::util::SearchOptions& rOpt,
     169             :                     const ::com::sun::star::lang::Locale& rLocale );
     170             : 
     171             :     /* replace back references in the replace string by the sub expressions from the search result */
     172             :     void ReplaceBackReferences( OUString& rReplaceStr, const OUString &rStr, const ::com::sun::star::util::SearchResult& rResult );
     173             : 
     174             : };
     175             : 
     176             : // ............................................................................
     177             : }   // namespace utl
     178             : // ............................................................................
     179             : 
     180             : #endif
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10