bump product version to 4.1.6.2
[LibreOffice.git] / tools / source / fsys / wldcrd.cxx
bloba38c66eda085b2b889f9b81b253cd77edb82f47d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/wldcrd.hxx>
22 /** Tests, whether a wildcard in pWild will match for pStr.
24 * If they match, return 1, otherwise 0.
26 * '*' in pWild means n chars for n > 0.
27 * '?' in pWild mean match exactly one character.
30 sal_uInt16 WildCard::ImpMatch( const char *pWild, const char *pStr ) const
32 int pos=0;
33 int flag=0;
35 while ( *pWild || flag )
37 switch (*pWild)
39 case '?':
40 if ( *pStr == '\0' )
41 return 0;
42 break;
44 default:
45 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
46 pWild++;
47 if ( *pWild != *pStr )
48 if ( !pos )
49 return 0;
50 else
51 pWild += pos;
52 else
53 break; // WARNING: may cause execution of next case
54 // in some circumstances!
55 case '*':
56 while ( *pWild == '*' )
57 pWild++;
58 if ( *pWild == '\0' )
59 return 1;
60 flag = 1;
61 pos = 0;
62 if ( *pStr == '\0' )
63 return ( *pWild == '\0' );
64 while ( *pStr && *pStr != *pWild )
66 if ( *pWild == '?' ) {
67 pWild++;
68 while ( *pWild == '*' )
69 pWild++;
71 pStr++;
72 if ( *pStr == '\0' )
73 return ( *pWild == '\0' );
75 break;
77 if ( *pWild != '\0' )
78 pWild++;
79 if ( *pStr != '\0' )
80 pStr++;
81 else
82 flag = 0;
83 if ( flag )
84 pos--;
86 return ( *pStr == '\0' ) && ( *pWild == '\0' );
89 sal_Bool WildCard::Matches( const String& rString ) const
91 OString aTmpWild = aWildString;
92 OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
94 sal_Int32 nSepPos;
96 if ( cSepSymbol != '\0' )
98 while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
100 // Check all splitted wildcards
101 if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) )
102 return sal_True;
103 aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
107 if ( ImpMatch( aTmpWild.getStr(), aString.getStr() ) )
108 return sal_True;
109 else
110 return sal_False;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */