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
27public:
28 RegexPattern() = delete;
29 RegexPattern(const SBuf &aPattern, int aFlags);
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
47private:
50
52 const int flags;
53
55 regex_t regex;
56};
57
58inline std::ostream &
59operator <<(std::ostream &os, const RegexPattern &rp)
60{
61 rp.print(os);
62 return os;
63}
64
65#endif /* SQUID_SRC_BASE_REGEXPATTERN_H */
66
std::ostream & operator<<(std::ostream &os, const RegexPattern &rp)
Definition: RegexPattern.h:59
bool match(const char *str) const
Definition: RegexPattern.h:40
bool caseSensitive() const
whether the regex differentiates letter case
Definition: RegexPattern.h:35
SBuf pattern
a regular expression in the text form, suitable for regcomp(3)
Definition: RegexPattern.h:49
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
RegexPattern(RegexPattern &&)=delete
bool isDot() const
whether this is an "any single character" regex (".")
Definition: RegexPattern.h:38
regex_t regex
a "compiled pattern buffer" filled by regcomp(3) for regexec(3)
Definition: RegexPattern.h:55
MEMPROXY_CLASS(RegexPattern)
RegexPattern()=delete
Definition: SBuf.h:94
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:415

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors