RegexPattern.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 "compat/GnuRegex.h"
13 #include "mem/forward.h"
14 #include "sbuf/SBuf.h"
15 
21 {
23 
24 public:
25  RegexPattern() = delete;
26  RegexPattern(const SBuf &aPattern, int aFlags);
27  ~RegexPattern();
28 
29  RegexPattern(RegexPattern &&) = delete; // no copying of any kind
30 
32  bool caseSensitive() const { return !(flags & REG_ICASE); }
33 
35  bool isDot() const { return pattern.length() == 1 && pattern[0] == '.'; }
36 
37  bool match(const char *str) const {return regexec(&regex,str,0,NULL,0)==0;}
38 
42  void print(std::ostream &os, const RegexPattern *previous = nullptr) const;
43 
44 private:
47 
49  const int flags;
50 
53 };
54 
55 inline std::ostream &
56 operator <<(std::ostream &os, const RegexPattern &rp)
57 {
58  rp.print(os);
59  return os;
60 }
61 
62 #endif /* SQUID_SRC_BASE_REGEXPATTERN_H */
63 
Definition: SBuf.h:94
bool match(const char *str) const
Definition: RegexPattern.h:37
#define REG_ICASE
Definition: GnuRegex.h:230
bool isDot() const
whether this is an "any single character" regex (".")
Definition: RegexPattern.h:35
RegexPattern()=delete
#define NULL
Definition: types.h:166
RegexPattern(RegexPattern &&)=delete
SBuf pattern
a regular expression in the text form, suitable for regcomp(3)
Definition: RegexPattern.h:46
regex_t regex
a "compiled pattern buffer" filled by regcomp(3) for regexec(3)
Definition: RegexPattern.h:52
bool caseSensitive() const
whether the regex differentiates letter case
Definition: RegexPattern.h:32
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:415
int regexec(regex_t *preg, const char *string, size_t nmatch, pmatch, int eflags) const
Definition: GnuRegex.c:4188
std::ostream & operator<<(std::ostream &os, const RegexPattern &rp)
Definition: RegexPattern.h:56
MEMPROXY_CLASS(RegexPattern)
const int flags
bitmask of REG_* flags for regcomp(3)
Definition: RegexPattern.h:49
void print(std::ostream &os, const RegexPattern *previous=nullptr) const
Definition: RegexPattern.cc:42

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors