RegExp.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: RegExp.hpp 2978 2011-11-23 03:36:44Z ocibu $"
00002 
00008 #ifndef GPSTK_REGEXP_HPP
00009 #define GPSTK_REGEXP_HPP
00010 
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //
00029 //  Wei Yan - Chinese Academy of Sciences . 2011
00030 //
00031 //============================================================================
00032 
00033 #include <string>
00034 #include <vector>
00035 #include <regex.h>
00036 
00037 // it appears that some systems don't define this...
00038 #if !defined(REG_NOERROR)
00039 #define REG_NOERROR 0
00040 #endif
00041 
00042 namespace gpstk
00043 {
00056    class RegExp   
00057    {
00058    public:
00059       typedef std::vector<std::string>::const_iterator Iterator;
00060 
00061    public:
00062       RegExp(const std::string& pattern = "*", 
00063              const int& options = REG_EXTENDED );      
00064       
00065       RegExp(const RegExp& right);
00066 
00067       virtual ~RegExp();
00068 
00069       int setPattern(const std::string& pattern);
00070    
00071       std::string pattern();
00072       
00073       bool match(const std::string& str);
00074 
00075       size_t size() const;
00076 
00077       size_t count() const;
00078 
00079       size_t matchedLength() const;
00080 
00081       std::vector<std::string> matchedStrings() const;
00082 
00083       std::string operator[] (size_t nth) const;
00084 
00085       Iterator begin() const;
00086 
00087       Iterator end() const;
00088 
00089       RegExp& operator=(const RegExp& right);
00090 
00091       bool operator!=(const RegExp& right);
00092 
00093       bool operator==(const RegExp& right);
00094 
00095       void set_eflags( int mask )   { _eflags |= mask; }
00096 
00097       void reset_eflags( int mask ) { _eflags &= ~mask;}
00098 
00099       //
00100       // static methods
00101       //
00102 
00103       static std::string replace(const std::string& str,
00104                                  const std::string& pattern,
00105                                  const std::string& newstr,
00106                                  const int& flag = 0);
00107 
00108    protected:
00109 
00110       void handleError(int rc, regex_t& re);
00111 
00112    protected:
00113         
00114       std::string _pattern;
00115       std::string _subject;
00116       std::vector<std::string> _matched;
00117 
00118       regex_t _regex;
00119       int _cflags;
00120       int _eflags;
00121       int _regerr; 
00122 
00123    };   // End of class 'RegExp'
00124    
00125 }   // End of namespace gpstk
00126 
00127 
00128 #endif  //GPSTK_REGEXP_HPP
00129 

Generated on Tue May 22 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1