casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RegexBase.h
Go to the documentation of this file.
1 //# RegexBase.h: Abstract interface class to regular expressions for String
2 //# Copyright (C) 2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef CASA_REGEXBASE_H
30 #define CASA_REGEXBASE_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 
40 // <summary>
41 // Abstract interface class to regular expressions for String
42 // </summary>
43 
44 // <use visibility=local>
45 
46 // <reviewed reviewer="Friso Olnon" date="1995/03/20" tests="tRegex" demos="">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> Regular expression syntax
51 // <li> <linkto class=String>String</linkto> class
52 // </prerequisite>
53 //
54 //
55 // <synopsis>
56 // This class provides a standard abstract interface to regular expression
57 // classes. This interface class is used in the String class, to enable
58 // the use of different actual regular expression classes.<br>
59 // Actual regular expression classes should define the following
60 // implementation (in addition, of course, to the standard constructors and
61 // assignments):
62 // <dl>
63 // <dt> String::size_type find(const Char *s, String::size_type len,
64 // Int &matchlen, String::size_type pos=0) const;
65 // <dd> Test if the regular expression occurs in string <src>s</src>.
66 // The return value gives the position of the first substring
67 // matching the regular expression (or String::npos if no match).
68 // The length of that substring is returned in <src>matchlen</src>.
69 // The string has <src>len</src> characters and the test starts at
70 // position <src>pos</src>. The string may contain null characters.
71 // </dl>
72 // The base class provides also default implementations of a few other methods
73 // used in the String classes' Casacore extensions. These implementations
74 // can, of course, be overwritten with more efficient specialised ones if
75 // necessary:
76 // <dl>
77 // <dt> String::size_type match(const Char *s,
78 // String::size_type len, String::size_type pos=0) const;
79 // <dd> Test if the regular expression matches string <src>s</src>.
80 // The return value gives the length of the matching string part,
81 // or String::npos if there is no match, or in case of an internal error.
82 // The string has <src>len</src> characters and the test starts at
83 // position <src>pos</src>. The string may contain null characters.
84 // The default implementation checks if the regular expression is found
85 // at position <src>pos</src> and with length (<src>len-pos</src>.
86 // <dt> String::size_type rfind(const Char *s, String::size_type len,
87 // Int &matchlen, String::size_type pos=npos) const;
88 // <dd> Test if the regular expression occurs in string <src>s</src>,
89 // searching reversed.
90 // The return value gives the position of the first substring
91 // matching the regular expression (or String::npos if no match).
92 // The length of that substring is returned in <src>matchlen</src>.
93 // The string has <src>len</src> characters and the test starts at
94 // position <src>pos</src> (or at end of string).
95 // The string may contain null characters. The default implementation
96 // starts checking for the regular expression at <src>pos</src> (or at
97 // the end of the string if that is less), and loops until it is
98 // found. Looping is by decrementing the search position until begin of
99 // string.
100 // <dt> String::size_type search(const Char *s, String::size_type len,
101 // Int &matchlen, Int pos=0) const;
102 // <dd> Test if the regular expression occurs in string <src>s</src>.
103 // The return value gives the position of the first substring
104 // matching the regular expression (or String::npos if no match).
105 // The length of that substring is returned in <src>matchlen</src>.
106 // The string has <src>len</src> characters and the test starts at
107 // position <src>pos</src>. The string may contain null characters.
108 // Following the special rule for Casacore string methods extensions:
109 // a negative position will indicate a reverse find. The default implementation
110 // checks for the sign of <src>pos</src> and calls either <src>find</src>
111 // or <src>rfind</src>.
112 // </dl>
113 //
114 // It is advisable to provide (static) methods to create strings from
115 // patterns and v.v., including file search patterns. See
116 // <linkto class=Regex>Regex</linkto> for an example.
117 // </synopsis>
118 //
119 // <example>
120 // See examples in appropriate regular expression implementation
121 // (e.g. <linkto class=Regex>Regex</linkto>)
122 // </example>
123 //
124 // <motivation>
125 // To allow for different regular expression classes in String matches
126 // </motivation>
127 //
128 // <todo asof="2001/05/22">
129 // <li> nothing I know of
130 // </todo>
131 
132 class RegexBase {
133  public:
134  //# Constructors
135  // Destructor
136  virtual ~RegexBase();
137  //# Member functions
138  // Search string <src>s</src> of length <src>len</src>, starting at position
139  // <src>pos</src>. Returned is the address of the first character of
140  // the substring found (or <src>String::npos</src> if not found). The
141  // matched length is returned in <src>matchlen</src>
142  virtual String::size_type find(const Char *s, String::size_type len,
143  Int &matchlen,
144  String::size_type pos=0) const=0;
145  // Match the string <src>s</src> of length <src>len</src> starting at
146  // position <src>pos</src>. Return the first matched character pointer, or
147  // <src>String::npos</src> if no match.
148  virtual String::size_type match(const Char *s,
149  String::size_type len,
150  String::size_type pos=0) const;
151  // Do an rfind() on the string <src>s</src> of length <src>len</src>
152  // starting at position <src>pos</src>. Return the position matched, or
153  // <src>String::npos</src>
154  virtual String::size_type rfind(const Char *s, String::size_type len,
155  Int &matchlen,
156  String::size_type pos=String::npos) const;
157  // Search string <src>s</src> of length <src>len</src>, starting at position
158  // <src>pos</src>. Returned is the address of the first character of
159  // the substring found (or <src>String::npos</src> if not found). The
160  // matched length is returned in <src>matchlen</src>. If <src>pos<0</src>
161  // do a reverse find.
162  virtual String::size_type search(const Char *s, String::size_type len,
163  Int &matchlen,
164  Int pos=0) const;
165  private:
166 
167 };
168 
169 
170 } //# NAMESPACE CASACORE - END
171 
172 #endif
173 
174 
int Int
Definition: aipstype.h:50
virtual ~RegexBase()
Destructor.
char Char
Definition: aipstype.h:46
virtual String::size_type rfind(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=String::npos) const
Do an rfind() on the string s of length len starting at position pos.
virtual String::size_type find(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=0) const =0
Search string s of length len, starting at position pos.
string::size_type size_type
Definition: String.h:231
Abstract interface class to regular expressions for String.
Definition: RegexBase.h:132
virtual String::size_type match(const Char *s, String::size_type len, String::size_type pos=0) const
Match the string s of length len starting at position pos.
static const size_type npos
Definition: String.h:244
virtual String::size_type search(const Char *s, String::size_type len, Int &matchlen, Int pos=0) const
Search string s of length len, starting at position pos.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42