casa
5.7.0-16
|
Regular expression class. More...
#include <Regex.h>
Public Member Functions | |
Regex () | |
Default constructor uses a zero-length regular expression. More... | |
Regex (const String &exp, Bool fast=False, Int sz=40, const Char *translation=0) | |
Construct a regular expression. More... | |
Regex (const Regex &that) | |
Copy constructor (copy semantics). More... | |
virtual | ~Regex () |
Regex & | operator= (const Regex &that) |
Assignment (copy semantics). More... | |
Regex & | operator= (const String &strng) |
const String & | regexp () const |
Get the regular expression string. More... | |
const Char * | transtable () const |
Get the translation table (can be a zero pointer). More... | |
virtual String::size_type | match (const Char *s, String::size_type len, String::size_type pos=0) const |
Test if the regular expression matches (part of) string s . More... | |
virtual String::size_type | search (const Char *s, String::size_type len, Int &matchlen, Int pos=0) const |
Test if the regular expression occurs in string s . More... | |
virtual String::size_type | find (const Char *s, String::size_type len, Int &matchlen, String::size_type pos=0) const |
Search string s of length len , starting at position pos . More... | |
Int | match_info (Int &start, Int &length, Int nth=0) const |
Return some internal cregex info. More... | |
Bool | OK () const |
Does it contain a valid Regex? More... | |
Public Member Functions inherited from casacore::RegexBase | |
virtual | ~RegexBase () |
Destructor. More... | |
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 . More... | |
Static Public Member Functions | |
static String | fromPattern (const String &pattern) |
Convert a shell-like pattern to a regular expression. More... | |
static String | fromSQLPattern (const String &pattern) |
Convert an SQL-like pattern to a regular expression. More... | |
static String | fromString (const String &strng) |
Convert a normal string to a regular expression. More... | |
static String | makeCaseInsensitive (const String &strng) |
Create a case-insensitive reular expression string from the given regular expression string. More... | |
Protected Member Functions | |
void | create (const String &, Int, Int, const Char *) |
Compile the regular expression. More... | |
void | dealloc () |
Deallocate the stuff allocated by create . More... | |
Protected Attributes | |
String | str |
Int | fastval |
Int | bufsz |
Char * | trans |
re_pattern_buffer * | buf |
re_registers * | reg |
Friends | |
ostream & | operator<< (ostream &ios, const Regex &exp) |
Write as ASCII. More... | |
Regular expression class.
Public interface
This class provides regular expression functionality, such as matching and searching in strings, comparison of expressions, and input/output. It is built on the regular expression functions in the GNU library (see files cregex.h and cregex.cc).
Apart from proper regular expressions, it also supports glob patterns (UNIX file name patterns) by means of a conversion to a proper regex. Also ordinary strings can be converted to a proper regex.
cregex.cc supports many syntaxes. Regex supports only one syntax, the extended regular expression with { and not \{ as a special character. The special characters are:
[abc]
. A hyphen can be used for a character range; e.g. [a-z]
. [^abc]
means any character but a, b, and c. If ^ is not the first character, it is a literal caret. If - is the last character, it is a literal hyphen. If ] is the first character, it is a literal closing bracket. [^[:upper:]]
is equal to [^A-Z]
. Note that [:upper:] is more portable, because A-Z fails for the EBCDIC character set. Special characters have to be escaped with a backslash to use them literally. Only inside the square brackets, escaping should not be done. See the man page of egrep or regexp for more information about regular expressions.
Several global Regex objects are predefined for common functionality.
The static member function fromPattern
converts a shell-like pattern to a String which can be used to create a Regex from it. A pattern has the following special characters:
{abc,defg}
means abc
or defg
. Brace expressions can be nested and can contain other special characters. The static member function fromSQLPattern
converts an SQL-like pattern to a String which can be used to create a Regex from it. A pattern has the following special characters:
The static member function fromString
converts a normal string to a regular expression. This function escapes characters in the string which are special in a regular expression. In this way a normal string can be passed to a function taking a regular expression.
The static member function makeCaseInsensitive
returns a new regular expression string containing the case-insensitive version of the given expression string.
In RXdouble the. is escaped via a backslash to get it literally. The second backslash is needed to escape the backslash in C++.
casacore::Regex::Regex | ( | ) |
Default constructor uses a zero-length regular expression.
casacore::Regex::Regex | ( | const String & | exp, |
Bool | fast = False , |
||
Int | sz = 40 , |
||
const Char * | translation = 0 |
||
) |
Construct a regular expression.
Optionally a fast map can be created, a buffer size can be given and a translation table (of 256 chars) can be applied. The translation table can, for instance, be used to map lowercase characters to uppercase. See cregex.cc (the extended regular expression matching and search library) for detailed information.
casacore::Regex::Regex | ( | const Regex & | that | ) |
Copy constructor (copy semantics).
|
virtual |
Compile the regular expression.
|
protected |
Deallocate the stuff allocated by create
.
|
virtual |
Search string s
of length len
, starting at position pos
.
Returned is the address of the first character of the substring found (or String::npos
if not found). The matched length is returned in matchlen
Implements casacore::RegexBase.
Convert a shell-like pattern to a regular expression.
This is useful for people who are more familiar with patterns than with regular expressions.
Convert an SQL-like pattern to a regular expression.
This is useful TaQL which mimics SQL.
Convert a normal string to a regular expression.
This consists of escaping the special characters. This is useful when one wants to provide a normal string (which may contain special characters) to a function working on regular expressions.
Create a case-insensitive reular expression string from the given regular expression string.
It does it by inserting the lowercase and uppercase version of characters in the input string into the output string.
|
virtual |
Test if the regular expression matches (part of) string s
.
The return value gives the length of the matching string part, or String::npos if there is no match or an error. The string has len
characters and the test starts at position pos
. The string may contain null characters. Negative p is allowed to match at end.
Tip: Use the appropriate String functions to test if a string matches a regular expression; Regex::match
is pretty low-level;
Reimplemented from casacore::RegexBase.
Return some internal cregex
info.
Assignment (copy semantics).
|
inline |
Get the regular expression string.
Definition at line 259 of file Regex.h.
References str.
Referenced by casacore::TaqlRegex::match().
|
virtual |
Test if the regular expression occurs in string s
.
The return value gives the position of the first substring matching the regular expression. The length of that substring is returned in matchlen
. The string has len
characters and the test starts at position pos
. The string may contain null characters. The search will do a reverse search if the pos given is less than 0.
Tip: Use the appropriate String functions to test if a regular expression occurs in a string; Regex::search
is pretty low-level;
Reimplemented from casacore::RegexBase.
|
inline |
|
friend |
Write as ASCII.
|
protected |
|
protected |
|
protected |
|
protected |
Definition at line 316 of file Regex.h.
Referenced by transtable().