00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019
00020
00021
00022 #ifndef SOME_PATHREGEX_HEADER
00023 #define SOME_PATHREGEX_HEADER
00024
00025 #include<string>
00026 #include<list>
00027 #include<algo.h>
00028
00029 namespace SOME
00030 {
00031
00032
00033 bool regex_eq( const std::string ®ex, const std::string &text )
00034 {
00035 if(text=="?")
00036 {
00037
00038 }
00039
00040
00041 else if(regex==text)
00042 {
00043 return true;
00044 }
00045 else if(text=="")
00046 {
00047 return regex_eq( regex, "?" );
00048 }
00049 else if(regex=="")
00050 {
00051 return false;
00052 }
00053
00054 if(regex[0]=='*')
00055 {
00056 if(regex=="*")
00057 return true;
00058 for(int i=0; i<text.size(); i++)
00059 {
00060 if(regex_eq( regex.substr(1), text.substr(i) ))
00061 return true;
00062 }
00063 return false;
00064
00065 }
00066 else if(regex[0]=='?')
00067 {
00068 if(text=="?")
00069 return false;
00070 else
00071 return regex_eq( regex.substr(1), text.substr(1) );
00072 }
00073 else
00074 {
00075 if(regex[0]==text[0])
00076 return regex_eq( regex.substr(1), text.substr(1) );
00077 else
00078 return false;
00079 }
00080
00081 return false;
00082 }
00083
00084 void regex_remove(std::list<string>::iterator first ,std::list<string>::iterator last, std::list<string> &thelist,const std::string regex )
00085 {
00086 std::list<string>::iterator it=thelist.begin();
00087 int size = thelist.size();
00088 for(int i=0; i<size; i++)
00089 {
00090
00091 if( !regex_eq( regex , *it ))
00092 {
00093 std::list<string>::iterator tempit = it;
00094 it++;
00095 thelist.erase(tempit);
00096 }
00097 else
00098 {
00099 it++;
00100 }
00101 }
00102 }
00103
00104 }
00105
00106 #endif