Main Page   Class Hierarchy   Compound List   File List   Compound Members  

some_algo.h

00001 /********************************************************************
00002 ** Copyright (C) 2000 SOMELib Project
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the
00016 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017 ** Boston, MA  02111-1307, USA.
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 &regex, const std::string &text )
00034 {
00035     if(text=="?")
00036     {
00037         //do nothing
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         //do regex stuff
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

Generated at Fri Dec 8 14:24:48 2000 for SOMELib by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000