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
)
51 break; // WARNING: may cause execution of next case
52 // in some circumstances!
54 while ( *pWild
== '*' )
61 return ( *pWild
== '\0' );
62 while ( *pStr
&& *pStr
!= *pWild
)
64 if ( *pWild
== '?' ) {
66 while ( *pWild
== '*' )
71 return ( *pWild
== '\0' );
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()));
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() ) )
101 aTmpWild
= aTmpWild
.copy(nSepPos
+ 1); // remove separator
105 if ( ImpMatch( aTmpWild
.getStr(), aString
.getStr() ) )
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */