regExpPosixI.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include <algorithm>
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
33:
34 preg_(nullptr),
35 ctrl_(0)
36{}
37
38
40:
41 preg_(rgx.preg_),
42 ctrl_(rgx.ctrl_)
43{
44 rgx.preg_ = nullptr;
45 rgx.ctrl_ = 0;
46}
47
48
50(
51 const char* pattern,
52 const bool ignoreCase
53)
54:
55 preg_(nullptr),
56 ctrl_(0)
57{
58 set(pattern, ignoreCase);
59}
60
61
63(
64 const std::string& pattern,
65 const bool ignoreCase
66)
67:
68 preg_(nullptr),
69 ctrl_(0)
70{
71 set(pattern, ignoreCase);
72}
73
74
75// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76
78{
79 clear();
80}
81
82
83// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
84
86{
87 return !preg_;
88}
89
90
92{
93 return preg_;
94}
95
96
98{
99 return (ctrl_ == ctrlType::NEGATED);
100}
101
102
103inline bool Foam::regExpPosix::negate(bool on) noexcept
104{
105 bool old(ctrl_ == ctrlType::NEGATED);
106
107 if (on)
108 {
109 if (ctrl_)
110 {
111 ctrl_ = ctrlType::NEGATED;
112 }
113 }
114 else if (old)
115 {
116 ctrl_ = ctrlType::NORMAL;
117 }
118
119 return old;
120}
121
122
123inline unsigned Foam::regExpPosix::ngroups() const
124{
125 return (preg_ && ctrl_ == ctrlType::NORMAL) ? preg_->re_nsub : 0;
126}
127
128
129inline bool Foam::regExpPosix::set(const char* pattern, bool ignoreCase)
130{
131 // Silently handle nullptr
132 return set_pattern
133 (
134 pattern,
135 (pattern ? std::char_traits<char>::length(pattern) : 0),
136 ignoreCase
137 );
138}
139
140
141inline bool Foam::regExpPosix::set(const std::string& pattern, bool ignoreCase)
142{
143 return set_pattern
144 (
145 pattern.data(),
146 pattern.length(),
147 ignoreCase
148 );
149}
150
151
152inline bool Foam::regExpPosix::search(const std::string& text) const
153{
154 if (!ctrl_)
155 {
156 return false;
157 }
158 else if (text.empty())
159 {
160 return (ctrl_ == ctrlType::NEGATED);
161 }
162
163 return std::string::npos != find(text);
164}
165
166
168{
169 if (this != &rgx)
170 {
171 // Self-swap is a no-op
172 std::swap(preg_, rgx.preg_);
173 std::swap(ctrl_, rgx.ctrl_);
174 }
175}
176
177
178// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
179
180inline bool Foam::regExpPosix::operator()(const std::string& text) const
181{
182 return match(text);
183}
184
185
187{
188 if (this != &rgx)
189 {
190 // Self-assignment is a no-op
191 clear();
192 swap(rgx);
193 }
194}
195
196
197inline void Foam::regExpPosix::operator=(const char* pattern)
198{
199 set(pattern);
200}
201
202
203inline void Foam::regExpPosix::operator=(const std::string& pattern)
204{
205 set(pattern);
206}
207
208
209// ************************************************************************* //
Ostream & operator()() const
Output stream (master only).
Definition: ensightCaseI.H:74
void negate()
Inplace negate.
Definition: faMatrix.C:800
Wrapper around POSIX extended regular expressions with some additional prefix-handling....
Definition: regExpPosix.H:85
void operator=(const regExpPosix &)=delete
Copy assignment - disallowed.
void swap(regExpPosix &rgx)
Swap contents.
Definition: regExpPosixI.H:167
bool empty() const noexcept
Return true if a precompiled expression does not exist.
Definition: regExpPosixI.H:85
bool set(const char *pattern, bool ignoreCase=false)
Compile pattern into a regular expression, optionally ignore case.
Definition: regExpPosixI.H:129
bool exists() const noexcept
Return true if a precompiled expression exists.
Definition: regExpPosixI.H:91
bool search(const std::string &text) const
Return true if the regex was found within the text.
Definition: regExpPosixI.H:152
bool negated() const noexcept
True if pattern matching is negated.
Definition: regExpPosixI.H:97
regExpPosix() noexcept
Default construct.
Definition: regExpPosixI.H:32
~regExpPosix()
Destructor.
Definition: regExpPosixI.H:77
unsigned ngroups() const
Definition: regExpPosixI.H:123
bool set() const
Are all the vector set.
Definition: triadI.H:76
patchWriters clear()
const direction noexcept
Definition: Scalar.H:223