LCOV - code coverage report
Current view: top level - tools/source/fsys - wldcrd.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 51 56.9 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 67 43.3 %

           Branch data     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                 :     299727 : sal_uInt16 WildCard::ImpMatch( const char *pWild, const char *pStr ) const
      31                 :            : {
      32                 :     299727 :     int    pos=0;
      33                 :     299727 :     int    flag=0;
      34                 :            : 
      35 [ +  + ][ -  + ]:     753426 :     while ( *pWild || flag )
                 [ +  + ]
      36                 :            :     {
      37      [ +  +  + ]:     752304 :         switch (*pWild)
      38                 :            :         {
      39                 :            :             case '?':
      40         [ -  + ]:      18000 :                 if ( *pStr == '\0' )
      41                 :          0 :                     return 0;
      42                 :      18000 :                 break;
      43                 :            : 
      44                 :            :             default:
      45 [ -  + ][ #  # ]:     541225 :                 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
                 [ #  # ]
      46                 :          0 :                     pWild++;
      47         [ +  + ]:     541225 :                 if ( *pWild != *pStr )
      48         [ +  - ]:     105526 :                     if ( !pos )
      49                 :     105526 :                         return 0;
      50                 :            :                     else
      51                 :          0 :                         pWild += pos;
      52                 :            :                 else
      53                 :     435699 :                     break;          // WARNING: may cause execution of next case
      54                 :            :                                     // in some circumstances!
      55                 :            :             case '*':
      56         [ +  + ]:     386158 :                 while ( *pWild == '*' )
      57                 :     193079 :                     pWild++;
      58         [ +  - ]:     193079 :                 if ( *pWild == '\0' )
      59                 :     193079 :                     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         [ +  - ]:     453699 :         if ( *pWild != '\0' )
      78                 :     453699 :             pWild++;
      79         [ +  - ]:     453699 :         if ( *pStr != '\0' )
      80                 :     453699 :             pStr++;
      81                 :            :         else
      82                 :          0 :             flag = 0;
      83         [ -  + ]:     453699 :         if ( flag )
      84                 :          0 :             pos--;
      85                 :            :     }
      86 [ +  + ][ +  - ]:     299727 :     return ( *pStr == '\0' ) && ( *pWild == '\0' );
      87                 :            : }
      88                 :            : 
      89                 :     299727 : sal_Bool WildCard::Matches( const String& rString ) const
      90                 :            : {
      91                 :     299727 :     rtl::OString aTmpWild = aWildString;
      92 [ +  - ][ +  - ]:     299727 :     rtl::OString aString(rtl::OUStringToOString(rString, osl_getThreadTextEncoding()));
                 [ +  - ]
      93                 :            : 
      94                 :            :     sal_Int32 nSepPos;
      95                 :            : 
      96         [ -  + ]:     299727 :     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 [ +  - ][ +  + ]:     299727 :     if ( ImpMatch( aTmpWild.getStr(), aString.getStr() ) )
     108                 :     194199 :         return sal_True;
     109                 :            :     else
     110                 :     299727 :         return sal_False;
     111                 :            : }
     112                 :            : 
     113                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10