Regex.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #ifndef __OASYS_REGEX_H__
00019 #define __OASYS_REGEX_H__
00020 
00021 #include <string>
00022 #include <sys/types.h>
00023 #include <regex.h>
00024 
00025 namespace oasys {
00026 
00027 class Regex {
00028 public:
00029     static const size_t MATCH_LIMIT = 8;
00030 
00031     static int match(const char* regex, const char* str, 
00032                      int cflags = 0, int rflags = 0);
00033 
00034     Regex(const char* regex, int cflags = 0);
00035     virtual ~Regex();
00036     
00037     int match(const char* str, int flags = 0);
00038 
00039     bool valid() { return compilation_err_ == 0; }
00040     
00041     int num_matches();
00042     const regmatch_t& get_match(size_t i);
00043 
00044     std::string regerror_str(int err);
00045     
00046 protected:
00047     int compilation_err_;
00048 
00049     regex_t    regex_;
00050     regmatch_t matches_[MATCH_LIMIT];
00051 };
00052 
00053 class Regsub : public Regex {
00054 public:
00055     static int subst(const char* regex, const char* str,
00056                      const char* sub_spec, std::string* result,
00057                      int cflags = 0, int rflags = 0);
00058     
00059     Regsub(const char* regex, const char* sub_spec, int flags = 0);
00060     ~Regsub();
00061         
00062     int subst(const char* str, std::string* result, int flags = 0);
00063 
00064 protected:
00065     std::string sub_spec_;
00066 };
00067     
00068 } // namespace oasys
00069 
00070 #endif /* __OASYS_REGEX_H__ */

Generated on Thu Jun 7 16:56:51 2007 for DTN Reference Implementation by  doxygen 1.5.1