Scopira  20080306
regex.h
1 
2 /*
3  * Copyright (c) 2004 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED__SCOPIRA_TOOL_REGEX_H__
15 #define __INCLUDED__SCOPIRA_TOOL_REGEX_H__
16 #include <scopira/tool/platform.h>
17 #ifndef PLATFORM_win32
18 
19 #include <stddef.h>
20 
21 #if (GCC_VERSION_MAJOR<3) || (GCC_VERSION_MAJOR==3 && GCC_VERSION_MINOR<3)
22 // this is a hack. gcc 3 turns on some regex() prototype stuff that
23 // gcc3 likes, but g++<3.3 doesnt. predefine this trickery here
24 #define __restrict_arr
25 #endif
26 
27 #include <regex.h>
28 
29 #include <string>
30 
31 #include <scopira/tool/array.h>
32 
33 namespace scopira
34 {
35  namespace tool
36  {
37  class regmatch;
38  class regex;
39  }
40 }
41 
48 {
49  public:
51  explicit regmatch(size_t sz);
52 
54  bool is_valid(size_t idx) const { return dm_ary[idx].rm_so != -1; }
55 
57  size_t begin(size_t idx) { return dm_ary[idx].rm_so; }
59  size_t end(size_t idx) { return dm_ary[idx].rm_eo; }
60 
62  size_t size(void) const { return dm_ary.size(); }
63 
65  size_t size_match(void) const;
66 
68  std::string substr(const std::string &base, size_t idx)
69  { assert(is_valid(idx)); return base.substr(begin(idx), end(idx)-begin(idx)); }
70 
71  friend class regex;
72 
73  private:
76 };
77 
84 {
85  public:
87  regex(void);
89  regex(const std::string &pattern);
91  ~regex();
92 
94  bool failed(void) const { return !dm_valid; }
95 
97  bool compile(const std::string &pattern);
98 
100  bool match(const std::string &s) const;
101 
103  bool match(const std::string &s, regmatch &mat) const;
104 
105  private:
106  bool dm_valid;
107  regex_t dm_re;
108 
109  private:
110  // not implemented - not legal
111  regex(const regex &);
112  // not implemented - not legal
113  void operator = (const regex&);
114 };
115 
116 #endif
117 #endif
118 
Definition: regex.h:83
Definition: archiveflow.h:20
bool failed(void) const
in a failed state?
Definition: regex.h:94
size_t begin(size_t idx)
get the base of a match
Definition: regex.h:57
Definition: regex.h:47
size_t size_match(void) const
gets the number of matches
std::string substr(const std::string &base, size_t idx)
convinience, get the substring
Definition: regex.h:68
bool is_valid(size_t idx) const
is this particular match valid?
Definition: regex.h:54
regmatch(size_t sz)
ctor
size_t size(void) const
gets the size
Definition: regex.h:62
size_t end(size_t idx)
get the end of the math
Definition: regex.h:59
size_t size(void) const
Definition: array.h:400