1*89b56da7SAndrew Rist /**************************************************************
2*89b56da7SAndrew Rist *
3*89b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*89b56da7SAndrew Rist * distributed with this work for additional information
6*89b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*89b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
10*89b56da7SAndrew Rist *
11*89b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*89b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist * KIND, either express or implied. See the License for the
17*89b56da7SAndrew Rist * specific language governing permissions and limitations
18*89b56da7SAndrew Rist * under the License.
19*89b56da7SAndrew Rist *
20*89b56da7SAndrew Rist *************************************************************/
21*89b56da7SAndrew Rist
22*89b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir #include <tools/wldcrd.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir /*************************************************************************
29cdf0e10cSrcweir |*
30cdf0e10cSrcweir |* WildCard::Match()
31cdf0e10cSrcweir |*
32cdf0e10cSrcweir |* Beschreibung WLDCRD.SDW
33cdf0e10cSrcweir |* Ersterstellung MA 19.06.91
34cdf0e10cSrcweir |* Letzte Aenderung MA 03.07.91
35cdf0e10cSrcweir |*
36cdf0e10cSrcweir *************************************************************************/
37cdf0e10cSrcweir
38cdf0e10cSrcweir /* Diese Methode ueberprueft, ob die Wilde Karte in pWild mit dem String
39cdf0e10cSrcweir * in pStr matscht.
40cdf0e10cSrcweir * Vertragen sich die beiden, so wird 1 zurueckgegeben, sonst 0.
41cdf0e10cSrcweir *
42cdf0e10cSrcweir * ein '*' in pWild bedeutet n beliebige Zeichen, mit n>=0
43cdf0e10cSrcweir * ein '?' in pWild bedeutet genau ein beliebiges Zeichen
44cdf0e10cSrcweir *
45cdf0e10cSrcweir */
46cdf0e10cSrcweir
ImpMatch(const char * pWild,const char * pStr) const47cdf0e10cSrcweir sal_uInt16 WildCard::ImpMatch( const char *pWild, const char *pStr ) const
48cdf0e10cSrcweir {
49cdf0e10cSrcweir int pos=0;
50cdf0e10cSrcweir int flag=0;
51cdf0e10cSrcweir
52cdf0e10cSrcweir while ( *pWild || flag )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir switch (*pWild)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir case '?':
57cdf0e10cSrcweir if ( *pStr == '\0' )
58cdf0e10cSrcweir return 0;
59cdf0e10cSrcweir break;
60cdf0e10cSrcweir
61cdf0e10cSrcweir default:
62cdf0e10cSrcweir if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
63cdf0e10cSrcweir pWild++;
64cdf0e10cSrcweir if ( *pWild != *pStr )
65cdf0e10cSrcweir if ( !pos )
66cdf0e10cSrcweir return 0;
67cdf0e10cSrcweir else
68cdf0e10cSrcweir pWild += pos;
69cdf0e10cSrcweir else
70cdf0e10cSrcweir break; // ACHTUNG laeuft unter bestimmten
71cdf0e10cSrcweir // Umstaenden in den nachsten case rein!!
72cdf0e10cSrcweir case '*':
73cdf0e10cSrcweir while ( *pWild == '*' )
74cdf0e10cSrcweir pWild++;
75cdf0e10cSrcweir if ( *pWild == '\0' )
76cdf0e10cSrcweir return 1;
77cdf0e10cSrcweir flag = 1;
78cdf0e10cSrcweir pos = 0;
79cdf0e10cSrcweir if ( *pStr == '\0' )
80cdf0e10cSrcweir return ( *pWild == '\0' );
81cdf0e10cSrcweir while ( *pStr && *pStr != *pWild )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir if ( *pWild == '?' ) {
84cdf0e10cSrcweir pWild++;
85cdf0e10cSrcweir while ( *pWild == '*' )
86cdf0e10cSrcweir pWild++;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir pStr++;
89cdf0e10cSrcweir if ( *pStr == '\0' )
90cdf0e10cSrcweir return ( *pWild == '\0' );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir break;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir if ( *pWild != '\0' )
95cdf0e10cSrcweir pWild++;
96cdf0e10cSrcweir if ( *pStr != '\0' )
97cdf0e10cSrcweir pStr++;
98cdf0e10cSrcweir else
99cdf0e10cSrcweir flag = 0;
100cdf0e10cSrcweir if ( flag )
101cdf0e10cSrcweir pos--;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir return ( *pStr == '\0' ) && ( *pWild == '\0' );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir /*************************************************************************
107cdf0e10cSrcweir |*
108cdf0e10cSrcweir |* WildCard::Matches()
109cdf0e10cSrcweir |*
110cdf0e10cSrcweir |* Beschreibung WLDCRD.SDW
111cdf0e10cSrcweir |* Ersterstellung MA 19.06.91
112cdf0e10cSrcweir |* Letzte Aenderung TH 02.02.96
113cdf0e10cSrcweir |*
114cdf0e10cSrcweir *************************************************************************/
115cdf0e10cSrcweir
Matches(const String & rString) const116cdf0e10cSrcweir sal_Bool WildCard::Matches( const String& rString ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir ByteString aTmpWild = aWildString;
119cdf0e10cSrcweir ByteString aString(rString, osl_getThreadTextEncoding());
120cdf0e10cSrcweir
121cdf0e10cSrcweir sal_uInt16 nSepPos;
122cdf0e10cSrcweir
123cdf0e10cSrcweir if ( cSepSymbol != '\0' )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir while ( (nSepPos = aTmpWild.Search( cSepSymbol )) != STRING_NOTFOUND )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir // alle getrennten WildCard's pruefen
128cdf0e10cSrcweir if ( ImpMatch( aTmpWild.Copy( 0, nSepPos ).GetBuffer(), aString.GetBuffer() ) )
129cdf0e10cSrcweir return sal_True;
130cdf0e10cSrcweir aTmpWild.Erase( 0, nSepPos + 1 ); // Trennsymbol entfernen
131cdf0e10cSrcweir }
132cdf0e10cSrcweir // und noch den hinter dem letzen Trennsymbol bzw. den einzigen
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir if ( ImpMatch( aTmpWild.GetBuffer(), aString.GetBuffer() ) )
136cdf0e10cSrcweir return sal_True;
137cdf0e10cSrcweir else
138cdf0e10cSrcweir return sal_False;
139cdf0e10cSrcweir }
140