1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
33 while ( *pWild
|| flag
)
43 if ( (*pWild
== '\\') && ((*(pWild
+1)=='?') || (*(pWild
+1) == '*')) )
45 if ( *pWild
!= *pStr
)
52 // WARNING/TODO: may cause execution of next case in some
56 while ( *pWild
== '*' )
63 return ( *pWild
== '\0' );
64 while ( *pStr
&& *pStr
!= *pWild
)
66 if ( *pWild
== '?' ) {
68 while ( *pWild
== '*' )
73 return ( *pWild
== '\0' );
86 return ( *pStr
== '\0' ) && ( *pWild
== '\0' );
89 bool WildCard::Matches( const OUString
& rString
) const
91 OString aTmpWild
= aWildString
;
92 OString
aString(OUStringToOString(rString
, osl_getThreadTextEncoding()));
96 if ( cSepSymbol
!= '\0' )
98 while ( (nSepPos
= aTmpWild
.indexOf(cSepSymbol
)) != -1 )
100 // Check all split wildcards
101 if ( ImpMatch( aTmpWild
.copy( 0, nSepPos
).getStr(), aString
.getStr() ) )
103 aTmpWild
= aTmpWild
.copy(nSepPos
+ 1); // remove separator
107 return ImpMatch( aTmpWild
.getStr(), aString
.getStr() );
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */