Squid Web Cache
master
Loading...
Searching...
No Matches
RegexPattern.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3
*
4
* Squid software is distributed under GPLv2+ license and includes
5
* contributions from numerous individuals and organizations.
6
* Please see the COPYING and CONTRIBUTORS files for details.
7
*/
8
9
#include "
squid.h
"
10
#include "
base/RegexPattern.h
"
11
#include "
base/TextException.h
"
12
#include "
debug/Stream.h
"
13
#include "
sbuf/Stream.h
"
14
15
#include <iostream>
16
#include <utility>
17
18
RegexPattern::RegexPattern
(
const
SBuf
&aPattern,
const
int
aFlags):
19
pattern(aPattern),
20
flags(aFlags)
21
{
22
memset(&
regex
, 0,
sizeof
(
regex
));
// paranoid; POSIX does not require this
23
if
(
const
auto
errCode = regcomp(&
regex
,
pattern
.
c_str
(),
flags
)) {
24
char
errBuf[256];
25
// for simplicity, ignore any error message truncation
26
(void)regerror(errCode, &
regex
, errBuf,
sizeof
(errBuf));
27
// POSIX examples show no regfree(®ex) after a regcomp() error;
28
// presumably, regcom() frees any allocated memory on failures
29
throw
TextException
(
ToSBuf
(
"POSIX regcomp(3) failure: ("
, errCode,
") "
, errBuf,
30
Debug::Extra
,
"regular expression: "
,
pattern
),
Here
());
31
}
32
33
debugs
(28, 2, *
this
);
34
}
35
36
RegexPattern::~RegexPattern
()
37
{
38
regfree(&
regex
);
39
}
40
41
void
42
RegexPattern::print
(std::ostream &os,
const
RegexPattern
*
const
previous)
const
43
{
44
// report context-dependent explicit options and delimiters
45
if
(!previous) {
46
// do not report default settings
47
if
(!
caseSensitive
())
48
os <<
"-i "
;
49
}
else
{
50
os <<
' '
;
// separate us from the previous value
51
52
// do not report same-as-previous (i.e. inherited) settings
53
if
(previous->
flags
!=
flags
)
54
os << (
caseSensitive
() ?
"+i "
:
"-i "
);
55
}
56
57
os <<
pattern
;
58
}
59
Here
#define Here()
source code location of the caller
Definition
Here.h:15
RegexPattern.h
TextException.h
Debug::Extra
static std::ostream & Extra(std::ostream &)
Definition
debug.cc:1316
RegexPattern
Definition
RegexPattern.h:24
RegexPattern::caseSensitive
bool caseSensitive() const
whether the regex differentiates letter case
Definition
RegexPattern.h:35
RegexPattern::pattern
SBuf pattern
a regular expression in the text form, suitable for regcomp(3)
Definition
RegexPattern.h:49
RegexPattern::flags
const int flags
bitmask of REG_* flags for regcomp(3)
Definition
RegexPattern.h:52
RegexPattern::print
void print(std::ostream &os, const RegexPattern *previous=nullptr) const
Definition
RegexPattern.cc:42
RegexPattern::~RegexPattern
~RegexPattern()
Definition
RegexPattern.cc:36
RegexPattern::regex
regex_t regex
a "compiled pattern buffer" filled by regcomp(3) for regexec(3)
Definition
RegexPattern.h:55
RegexPattern::RegexPattern
RegexPattern()=delete
SBuf
Definition
SBuf.h:94
SBuf::c_str
const char * c_str()
Definition
SBuf.cc:516
TextException
an std::runtime_error with thrower location info
Definition
TextException.h:21
Stream.h
debugs
#define debugs(SECTION, LEVEL, CONTENT)
Definition
Stream.h:192
Stream.h
ToSBuf
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition
Stream.h:63
squid.h
squid
src
base
RegexPattern.cc
Generated by
1.9.8