OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
RegularExpression.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: RegularExpression.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: RegularExpression.
10// This class provides a simple interface to the POSIX-compliant
11// regcomp/regexec package.
12//
13// ------------------------------------------------------------------------
14//
15// $Date: 2000/03/27 09:33:48 $
16// $Author: Andreas Adelmann $
17//
18// ------------------------------------------------------------------------
19
21#include <regex.h>
22#include <algorithm>
23#include <cstdlib>
24#include <cstring>
25#include <functional>
26#include <iomanip>
27#include <iostream>
28#include <new>
30
31// Class RegularExpression::Expression
32// ------------------------------------------------------------------------
33
34class RegularExpression::Expression : public regex_t {};
35
36// Class RegularExpression
37// ------------------------------------------------------------------------
38
39RegularExpression::RegularExpression(const std::string& pattern, bool ignore)
40 : patt(pattern), caseIgnore(ignore) {
41 init();
42}
43
45 : patt(rhs.patt), caseIgnore(rhs.caseIgnore) {
46 init();
47}
48
50
51bool RegularExpression::match(const std::string& s) const {
52 int rc = state;
53
54 if (rc == 0) {
55 int nmatch = 0;
56 regmatch_t* pmatch = 0;
57 int flags = 0;
58 rc = regexec(expr, s.data(), nmatch, pmatch, flags);
59 if (rc == 0) {
60 return true;
61 } else if (rc == REG_NOMATCH) {
62 return false;
63 }
64 }
65
66 char buffer[80];
67 regerror(rc, expr, buffer, 80);
68 throw OpalException("RegularExpression::match()", buffer);
69}
70
71bool RegularExpression::OK() const { return state == 0 && expr != 0; }
72
74 expr = (Expression*)malloc(sizeof(regex_t));
75 int flags = REG_NOSUB;
76 if (caseIgnore) flags |= REG_ICASE;
77 state = regcomp(expr, patt.c_str(), flags);
78}
A regular expression.
bool match(const std::string &s) const
Match a string against the pattern.
RegularExpression(const std::string &pattern, bool ignore=false)
Constructor.
const std::string patt
bool OK() const
Check the regular expression for sanity.