RegexPattern.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 #ifndef SQUID_SRC_BASE_REGEXPATTERN_H
10 #define SQUID_SRC_BASE_REGEXPATTERN_H
11 
12 #include "mem/forward.h"
13 #include "sbuf/SBuf.h"
14 
15 #if HAVE_REGEX_H
16 #include <regex.h>
17 #endif
18 
24 {
26 
27 public:
28  RegexPattern() = delete;
29  RegexPattern(const SBuf &aPattern, int aFlags);
30  ~RegexPattern();
31 
32  RegexPattern(RegexPattern &&) = delete; // no copying of any kind
33 
35  bool caseSensitive() const { return !(flags & REG_ICASE); }
36 
38  bool isDot() const { return pattern.length() == 1 && pattern[0] == '.'; }
39 
40  bool match(const char *str) const {return regexec(&regex,str,0,nullptr,0)==0;}
41 
45  void print(std::ostream &os, const RegexPattern *previous = nullptr) const;
46 
47 private:
50 
52  const int flags;
53 
55  regex_t regex;
56 };
57 
58 inline std::ostream &
59 operator <<(std::ostream &os, const RegexPattern &rp)
60 {
61  rp.print(os);
62  return os;
63 }
64 
65 #endif /* SQUID_SRC_BASE_REGEXPATTERN_H */
66 
Definition: SBuf.h:93
bool match(const char *str) const
Definition: RegexPattern.h:40
bool isDot() const
whether this is an "any single character" regex (".")
Definition: RegexPattern.h:38
RegexPattern()=delete
SBuf pattern
a regular expression in the text form, suitable for regcomp(3)
Definition: RegexPattern.h:49
regex_t regex
a "compiled pattern buffer" filled by regcomp(3) for regexec(3)
Definition: RegexPattern.h:55
bool caseSensitive() const
whether the regex differentiates letter case
Definition: RegexPattern.h:35
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:419
std::ostream & operator<<(std::ostream &os, const RegexPattern &rp)
Definition: RegexPattern.h:59
MEMPROXY_CLASS(RegexPattern)
const int flags
bitmask of REG_* flags for regcomp(3)
Definition: RegexPattern.h:52
void print(std::ostream &os, const RegexPattern *previous=nullptr) const
Definition: RegexPattern.cc:42

 

Introduction

Documentation

Support

Miscellaneous