Update ooo320-m1
[ooovba.git] / tools / source / fsys / wldcrd.cxx
blob6264aee0fbcffd2ef790d7f27d4731dd038cff94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wldcrd.cxx,v $
10 * $Revision: 1.5 $
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 /*************************************************************************
37 |* WildCard::Match()
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
46 * in pStr matscht.
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
56 int pos=0;
57 int flag=0;
59 while ( *pWild || flag )
61 switch (*pWild)
63 case '?':
64 if ( *pStr == '\0' )
65 return 0;
66 break;
68 default:
69 if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
70 pWild++;
71 if ( *pWild != *pStr )
72 if ( !pos )
73 return 0;
74 else
75 pWild += pos;
76 else
77 break; // ACHTUNG laeuft unter bestimmten
78 // Umstaenden in den nachsten case rein!!
79 case '*':
80 while ( *pWild == '*' )
81 pWild++;
82 if ( *pWild == '\0' )
83 return 1;
84 flag = 1;
85 pos = 0;
86 if ( *pStr == '\0' )
87 return ( *pWild == '\0' );
88 while ( *pStr && *pStr != *pWild )
90 if ( *pWild == '?' ) {
91 pWild++;
92 while ( *pWild == '*' )
93 pWild++;
95 pStr++;
96 if ( *pStr == '\0' )
97 return ( *pWild == '\0' );
99 break;
101 if ( *pWild != '\0' )
102 pWild++;
103 if ( *pStr != '\0' )
104 pStr++;
105 else
106 flag = 0;
107 if ( flag )
108 pos--;
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());
128 USHORT nSepPos;
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() ) )
136 return TRUE;
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() ) )
143 return TRUE;
144 else
145 return FALSE;