LCOV - code coverage report
Current view: top level - tools/source/fsys - wldcrd.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 29 51 56.9 %
Date: 2014-04-11 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             :  * '*' in pWild means n chars for n > 0.
      25             :  * '?' in pWild mean match exactly one character.
      26             :  *
      27             :  */
      28      561427 : bool WildCard::ImpMatch( const char *pWild, const char *pStr ) const
      29             : {
      30      561427 :     int    pos=0;
      31      561427 :     int    flag=0;
      32             : 
      33     2660045 :     while ( *pWild || flag )
      34             :     {
      35     2097729 :         switch (*pWild)
      36             :         {
      37             :             case '?':
      38       10304 :                 if ( *pStr == '\0' )
      39           0 :                     return false;
      40       10304 :                 break;
      41             : 
      42             :             default:
      43     1940221 :                 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
      44           0 :                     pWild++;
      45     1940221 :                 if ( *pWild != *pStr )
      46      413334 :                     if ( !pos )
      47      413334 :                         return false;
      48             :                     else
      49           0 :                         pWild += pos;
      50             :                 else
      51     1526887 :                     break;          // WARNING: may cause execution of next case
      52             :                                     // in some circumstances!
      53             :             case '*':
      54      441612 :                 while ( *pWild == '*' )
      55      147204 :                     pWild++;
      56      147204 :                 if ( *pWild == '\0' )
      57      147204 :                     return true;
      58           0 :                 flag = 1;
      59           0 :                 pos  = 0;
      60           0 :                 if ( *pStr == '\0' )
      61           0 :                     return ( *pWild == '\0' );
      62           0 :                 while ( *pStr && *pStr != *pWild )
      63             :                 {
      64           0 :                     if ( *pWild == '?' ) {
      65           0 :                         pWild++;
      66           0 :                         while ( *pWild == '*' )
      67           0 :                             pWild++;
      68             :                     }
      69           0 :                     pStr++;
      70           0 :                     if ( *pStr == '\0' )
      71           0 :                         return ( *pWild == '\0' );
      72             :                 }
      73           0 :                 break;
      74             :         }
      75     1537191 :         if ( *pWild != '\0' )
      76     1537191 :             pWild++;
      77     1537191 :         if ( *pStr != '\0' )
      78     1537191 :             pStr++;
      79             :         else
      80           0 :             flag = 0;
      81     1537191 :         if ( flag )
      82           0 :             pos--;
      83             :     }
      84         889 :     return ( *pStr == '\0' ) && ( *pWild == '\0' );
      85             : }
      86             : 
      87      561427 : bool WildCard::Matches( const OUString& rString ) const
      88             : {
      89      561427 :     OString aTmpWild = aWildString;
      90     1122854 :     OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
      91             : 
      92             :     sal_Int32 nSepPos;
      93             : 
      94      561427 :     if ( cSepSymbol != '\0' )
      95             :     {
      96           0 :         while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
      97             :         {
      98             :             // Check all splitted wildcards
      99           0 :             if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) )
     100           0 :                 return true;
     101           0 :             aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
     102             :         }
     103             :     }
     104             : 
     105      561427 :     if ( ImpMatch( aTmpWild.getStr(), aString.getStr() ) )
     106      148092 :         return true;
     107             :     else
     108      974762 :         return false;
     109             : }
     110             : 
     111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10