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
20
#include "
Utilities/RegularExpression.h
"
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>
29
#include "
Utilities/OpalException.h
"
30
31
// Class RegularExpression::Expression
32
// ------------------------------------------------------------------------
33
34
class
RegularExpression::Expression
:
public
regex_t {};
35
36
// Class RegularExpression
37
// ------------------------------------------------------------------------
38
39
RegularExpression::RegularExpression
(
const
std::string& pattern,
bool
ignore)
40
: patt(pattern), caseIgnore(ignore) {
41
init
();
42
}
43
44
RegularExpression::RegularExpression
(
const
RegularExpression
& rhs)
45
: patt(rhs.patt), caseIgnore(rhs.caseIgnore) {
46
init
();
47
}
48
49
RegularExpression::~RegularExpression
() { ::regfree(
expr
); }
50
51
bool
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
71
bool
RegularExpression::OK
()
const
{
return
state
== 0 &&
expr
!= 0; }
72
73
void
RegularExpression::init
() {
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
}
OpalException.h
RegularExpression.h
OpalException
Definition
OpalException.h:30
RegularExpression::Expression
Definition
RegularExpression.cpp:34
RegularExpression
A regular expression.
Definition
RegularExpression.h:30
RegularExpression::match
bool match(const std::string &s) const
Match a string against the pattern.
Definition
RegularExpression.cpp:51
RegularExpression::RegularExpression
RegularExpression(const std::string &pattern, bool ignore=false)
Constructor.
Definition
RegularExpression.cpp:39
RegularExpression::state
int state
Definition
RegularExpression.h:64
RegularExpression::patt
const std::string patt
Definition
RegularExpression.h:54
RegularExpression::OK
bool OK() const
Check the regular expression for sanity.
Definition
RegularExpression.cpp:71
RegularExpression::caseIgnore
bool caseIgnore
Definition
RegularExpression.h:57
RegularExpression::init
void init()
Definition
RegularExpression.cpp:73
RegularExpression::expr
Expression * expr
Definition
RegularExpression.h:61
RegularExpression::~RegularExpression
~RegularExpression()
Definition
RegularExpression.cpp:49
src
Utilities
RegularExpression.cpp
Generated on Mon Jun 1 2026 10:40:53 for OPALX (Object Oriented Parallel Accelerator Library for Exascal) by
1.9.8