1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wldcrd.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
33 #include <tools/wldcrd.hxx>
35 /*************************************************************************
39 |* Beschreibung WLDCRD.SDW
40 |* Ersterstellung MA 19.06.91
41 |* Letzte Aenderung MA 03.07.91
43 *************************************************************************/
45 /* Diese Methode ueberprueft, ob die Wilde Karte in pWild mit dem String
47 * Vertragen sich die beiden, so wird 1 zurueckgegeben, sonst 0.
49 * ein '*' in pWild bedeutet n beliebige Zeichen, mit n>=0
50 * ein '?' in pWild bedeutet genau ein beliebiges Zeichen
54 USHORT
WildCard::ImpMatch( const char *pWild
, const char *pStr
) const
59 while ( *pWild
|| flag
)
69 if ( (*pWild
== '\\') && ((*(pWild
+1)=='?') || (*(pWild
+1) == '*')) )
71 if ( *pWild
!= *pStr
)
77 break; // ACHTUNG laeuft unter bestimmten
78 // Umstaenden in den nachsten case rein!!
80 while ( *pWild
== '*' )
87 return ( *pWild
== '\0' );
88 while ( *pStr
&& *pStr
!= *pWild
)
90 if ( *pWild
== '?' ) {
92 while ( *pWild
== '*' )
97 return ( *pWild
== '\0' );
101 if ( *pWild
!= '\0' )
110 return ( *pStr
== '\0' ) && ( *pWild
== '\0' );
113 /*************************************************************************
115 |* WildCard::Matches()
117 |* Beschreibung WLDCRD.SDW
118 |* Ersterstellung MA 19.06.91
119 |* Letzte Aenderung TH 02.02.96
121 *************************************************************************/
123 BOOL
WildCard::Matches( const String
& rString
) const
125 ByteString aTmpWild
= aWildString
;
126 ByteString
aString(rString
, osl_getThreadTextEncoding());
130 if ( cSepSymbol
!= '\0' )
132 while ( (nSepPos
= aTmpWild
.Search( cSepSymbol
)) != STRING_NOTFOUND
)
134 // alle getrennten WildCard's pruefen
135 if ( ImpMatch( aTmpWild
.Copy( 0, nSepPos
).GetBuffer(), aString
.GetBuffer() ) )
137 aTmpWild
.Erase( 0, nSepPos
+ 1 ); // Trennsymbol entfernen
139 // und noch den hinter dem letzen Trennsymbol bzw. den einzigen
142 if ( ImpMatch( aTmpWild
.GetBuffer(), aString
.GetBuffer() ) )