LCOV - code coverage report
Current view: top level - libreoffice/tools/source/fsys - wldcrd.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 51 54.9 %
Date: 2012-12-27 Functions: 2 2 100.0 %
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             : 
      20             : #include <tools/wldcrd.hxx>
      21             : 
      22             : /** Tests, whether a wildcard in pWild will match for pStr.
      23             :  *
      24             :  * If they match, return 1, otherwise 0.
      25             :  *
      26             :  * '*' in pWild means n chars for n > 0.
      27             :  * '?' in pWild mean match exactly one character.
      28             :  *
      29             :  */
      30       61887 : sal_uInt16 WildCard::ImpMatch( const char *pWild, const char *pStr ) const
      31             : {
      32       61887 :     int    pos=0;
      33       61887 :     int    flag=0;
      34             : 
      35      305830 :     while ( *pWild || flag )
      36             :     {
      37      243943 :         switch (*pWild)
      38             :         {
      39             :             case '?':
      40        1984 :                 if ( *pStr == '\0' )
      41           0 :                     return 0;
      42        1984 :                 break;
      43             : 
      44             :             default:
      45      235356 :                 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
      46           0 :                     pWild++;
      47      235356 :                 if ( *pWild != *pStr )
      48       55284 :                     if ( !pos )
      49       55284 :                         return 0;
      50             :                     else
      51           0 :                         pWild += pos;
      52             :                 else
      53      180072 :                     break;          // WARNING: may cause execution of next case
      54             :                                     // in some circumstances!
      55             :             case '*':
      56       19809 :                 while ( *pWild == '*' )
      57        6603 :                     pWild++;
      58        6603 :                 if ( *pWild == '\0' )
      59        6603 :                     return 1;
      60           0 :                 flag = 1;
      61           0 :                 pos  = 0;
      62           0 :                 if ( *pStr == '\0' )
      63           0 :                     return ( *pWild == '\0' );
      64           0 :                 while ( *pStr && *pStr != *pWild )
      65             :                 {
      66           0 :                     if ( *pWild == '?' ) {
      67           0 :                         pWild++;
      68           0 :                         while ( *pWild == '*' )
      69           0 :                             pWild++;
      70             :                     }
      71           0 :                     pStr++;
      72           0 :                     if ( *pStr == '\0' )
      73           0 :                         return ( *pWild == '\0' );
      74             :                 }
      75           0 :                 break;
      76             :         }
      77      182056 :         if ( *pWild != '\0' )
      78      182056 :             pWild++;
      79      182056 :         if ( *pStr != '\0' )
      80      182056 :             pStr++;
      81             :         else
      82           0 :             flag = 0;
      83      182056 :         if ( flag )
      84           0 :             pos--;
      85             :     }
      86           0 :     return ( *pStr == '\0' ) && ( *pWild == '\0' );
      87             : }
      88             : 
      89       61887 : sal_Bool WildCard::Matches( const String& rString ) const
      90             : {
      91       61887 :     rtl::OString aTmpWild = aWildString;
      92       61887 :     rtl::OString aString(rtl::OUStringToOString(rString, osl_getThreadTextEncoding()));
      93             : 
      94             :     sal_Int32 nSepPos;
      95             : 
      96       61887 :     if ( cSepSymbol != '\0' )
      97             :     {
      98           0 :         while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
      99             :         {
     100             :             // Check all splitted wildcards
     101           0 :             if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) )
     102           0 :                 return sal_True;
     103           0 :             aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
     104             :         }
     105             :     }
     106             : 
     107       61887 :     if ( ImpMatch( aTmpWild.getStr(), aString.getStr() ) )
     108        6603 :         return sal_True;
     109             :     else
     110       55284 :         return sal_False;
     111             : }
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10