wildcards.h

00001 #ifndef WILDCARD_H_INCLUDED
00002 #define WILDCARD_H_INCLUDED
00003 
00004 // Copyright (C) 1996 - 2002 Florian Schintke
00005 //
00006 // This is free software; you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation; either version 2, or (at your option) any later
00009 // version.
00010 //
00011 // Thanks to the E.S.O. - ACS project that has done this C++ interface
00012 // to the wildcards pttern matching algorithm
00013 
00014 #ifndef __cplusplus
00015 #error This is a C++ include file and cannot be used from plain C
00016 #endif
00017 
00018 // Implementation of the UN*X wildcards
00019 // Supported wild-characters: '*', '?'; sets: [a-z], '!' negation
00020 // Examples:
00021 //       '[a-g]l*i?n' matches 'florian'
00022 //       '[!abc]*e' matches 'smile'
00023 //       '[-z] matches 'a'
00024 
00025 class Wildcard
00026 {
00027 public:
00028   // This function implements the UN*X wildcards and returns:
00029   // 0 - if *wildcard does not match *test
00030   // 1 - if *wildcard matches *test
00031   static int wildcardfit (const char *wildcard, const char *test);
00032        
00033 private:
00034   // Scans a set of characters and returns 0 if the set mismatches at this
00035   // position in the teststring and 1 if it is matching
00036   // wildcard is set to the closing ] and test is unmodified if mismatched
00037   // and otherwise the char pointer is pointing to the next character
00038   static int set (const char **wildcard, const char **test);
00039 
00040   // Scans an asterisk
00041   static int asterisk (const char **wildcard, const char **test);
00042 };
00043 
00044 #endif
00045 
00046