Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

matcher.hh

00001 /*
00002 *  Name:      matcher.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Regular expression matcher
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_TEXT_REGEX_MATCHER__
00027 #define _MPCL_TEXT_REGEX_MATCHER__
00028 
00029 #include <cstring>
00030 #include <sstream>
00031 #include "../../util/collection/string_to_string_map.hh"
00032 #include "../string.hh"
00033 #include "defs.hh"
00034 
00035 
00037 namespace mpcl
00038 {
00039 
00041   namespace text
00042   {
00043 
00045     namespace regex
00046     {
00047 
00048       using util::collection::TStringToStringMap;
00049 
00073       class TMatcher
00074       {
00075 
00076         private:
00077 
00079           bool   gCaseSensitive;
00080 
00082           bool   gLocalStream;
00083 
00085           std::basic_istream<char>*   ptSourceIstream;
00086 
00088           TStringToStringMap   tTerminalMap;
00089 
00090 
00091         public:
00092 
00093           //
00094           //  C O N S T R U C T O R S
00095           //
00096 
00098           TMatcher (void)           :
00099             gCaseSensitive  (true)  ,
00100             gLocalStream    (false) ,
00101             ptSourceIstream (NULL)  ,
00102             tTerminalMap    ()      {}
00103 
00108           TMatcher (std::basic_istream<char>& rtISTREAM) :
00109             gCaseSensitive  (true)                       ,
00110             gLocalStream    (false)                      ,
00111             ptSourceIstream (&rtISTREAM)                 ,
00112             tTerminalMap    ()
00113           {
00114             checkStream();
00115           }
00116 
00121           TMatcher (const std::string& rySTRING)                            :
00122             gCaseSensitive  (true)                                          ,
00123             gLocalStream    (true)                                          ,
00124             ptSourceIstream (new std::basic_istringstream<char> (rySTRING)) ,
00125             tTerminalMap    ()
00126           {
00127             if ( !rySTRING.empty() )
00128             {
00129               checkStream();
00130             }
00131           }
00132 
00137           TMatcher (const char* pkcSTRING)                                   :
00138             gCaseSensitive  (true)                                           ,
00139             gLocalStream    (true)                                           ,
00140             ptSourceIstream (new std::basic_istringstream<char> (pkcSTRING)) ,
00141             tTerminalMap    ()
00142           {
00143             if ( pkcSTRING && std::strlen (pkcSTRING) )
00144             {
00145               checkStream();
00146             }
00147           }
00148 
00150           ~TMatcher (void)
00151           {
00152             clearStream();
00153           }
00154 
00156           void clearDefinitions (void);
00157 
00164           void define (const char* pkcTERMINAL, const char* pkcDEFINITION);
00165 
00172           void redefine (const char* pkcTERMINAL, const char* pkcDEFINITION);
00173 
00178           void setCaseSensitiveness (bool gTRUTH);
00179 
00184           void setInput (const char* pkcSTRING);
00185 
00190           void setInput (const std::string& rkySTRING)
00191           {
00192             setInput (rkySTRING.c_str());
00193           }
00194 
00199           void setInput (std::basic_istream<char>& rtISTREAM);
00200 
00201 
00202         public:
00203 
00204           //
00205           //  S E L E C T O R S
00206           //
00207 
00223           size_t scan (const char* pkcPATTERN_STRING...) const;
00224 
00232           bool match (const char* pkcPATTERN_STRING) const;
00233 
00234 
00235         protected:
00236 
00237           //
00238           //  C O N S T R U C T O R S
00239           //
00240 
00242           void clearStream (void);
00243 
00244 
00245         protected:
00246 
00247           //
00248           //  S E L E C T O R S
00249           //
00250 
00252           void checkStream (void) const;
00253 
00261           TString instantiate (const char* pkcPATTERN_STRING) const;
00262 
00271           bool matchChars (char cSOURCE, const char* pkcPATTERN_STRING ) const;
00272 
00273       };  // class TMatcher
00274 
00275     }  // namespace regex
00276 
00277   }  // namespace text
00278 
00279 }  // namespace mpcl
00280 
00281 
00282 #endif  // not _MPCL_TEXT_REGEX_MATCHER__

Generated on Mon Oct 13 02:35:23 2003 for MPCL by doxygen1.2.18