fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / tools / source / fsys / wldcrd.cxx
blob4adfb7c3850ea668f23971e826466e70861d56bc
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 * '*' in pWild means n chars for n > 0.
25 * '?' in pWild mean match exactly one character.
28 bool WildCard::ImpMatch( const char *pWild, const char *pStr )
30 int pos=0;
31 int flag=0;
33 while ( *pWild || flag )
35 switch (*pWild)
37 case '?':
38 if ( *pStr == '\0' )
39 return false;
40 break;
42 default:
43 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
44 pWild++;
45 if ( *pWild != *pStr )
46 if ( !pos )
47 return false;
48 else
49 pWild += pos;
50 else
51 break; // WARNING: may cause execution of next case
52 // in some circumstances!
53 case '*':
54 while ( *pWild == '*' )
55 pWild++;
56 if ( *pWild == '\0' )
57 return true;
58 flag = 1;
59 pos = 0;
60 if ( *pStr == '\0' )
61 return ( *pWild == '\0' );
62 while ( *pStr && *pStr != *pWild )
64 if ( *pWild == '?' ) {
65 pWild++;
66 while ( *pWild == '*' )
67 pWild++;
69 pStr++;
70 if ( *pStr == '\0' )
71 return ( *pWild == '\0' );
73 break;
75 if ( *pWild != '\0' )
76 pWild++;
77 if ( *pStr != '\0' )
78 pStr++;
79 else
80 flag = 0;
81 if ( flag )
82 pos--;
84 return ( *pStr == '\0' ) && ( *pWild == '\0' );
87 bool WildCard::Matches( const OUString& rString ) const
89 OString aTmpWild = aWildString;
90 OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
92 sal_Int32 nSepPos;
94 if ( cSepSymbol != '\0' )
96 while ( (nSepPos = aTmpWild.indexOf(cSepSymbol)) != -1 )
98 // Check all splitted wildcards
99 if ( ImpMatch( aTmpWild.copy( 0, nSepPos ).getStr(), aString.getStr() ) )
100 return true;
101 aTmpWild = aTmpWild.copy(nSepPos + 1); // remove separator
105 if ( ImpMatch( aTmpWild.getStr(), aString.getStr() ) )
106 return true;
107 else
108 return false;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */