]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/RegexPattern.cc
e56b76faf5156fc7de7cbbbe3adb310acb95fe0e
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
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.
10 #include "base/RegexPattern.h"
11 #include "base/TextException.h"
12 #include "debug/Stream.h"
13 #include "sbuf/Stream.h"
18 RegexPattern::RegexPattern(const SBuf
&aPattern
, const int aFlags
):
22 memset(®ex
, 0, sizeof(regex
)); // paranoid; POSIX does not require this
23 if (const auto errCode
= regcomp(®ex
, pattern
.c_str(), flags
)) {
25 // for simplicity, ignore any error message truncation
26 (void)regerror(errCode
, ®ex
, 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());
36 RegexPattern::~RegexPattern()
42 RegexPattern::print(std::ostream
&os
, const RegexPattern
* const previous
) const
44 // report context-dependent explicit options and delimiters
46 // do not report default settings
50 os
<< ' '; // separate us from the previous value
52 // do not report same-as-previous (i.e. inherited) settings
53 if (previous
->flags
!= flags
)
54 os
<< (caseSensitive() ? "+i " : "-i ");