CharacterSet.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_PARSER_CHARACTERSET_H
10 #define _SQUID_SRC_PARSER_CHARACTERSET_H
11 
12 #include <initializer_list>
13 #include <iosfwd>
14 #include <vector>
15 
18 {
19 public:
20  typedef std::vector<uint8_t> Storage;
21 
23  explicit CharacterSet(const char *label = "anonymous", const char * const chars = "");
24 
28  CharacterSet(const char *label, unsigned char low, unsigned char high);
29 
33  CharacterSet(const char *label, std::initializer_list<std::pair<uint8_t,uint8_t>> ranges);
34 
36  bool isEmpty() const { return chars_.empty(); }
37 
39  bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] != 0;}
40 
42  CharacterSet & add(const unsigned char c);
43 
45  CharacterSet & remove(const unsigned char c);
46 
48  CharacterSet & addRange(unsigned char low, unsigned char high);
49 
52 
55 
58  CharacterSet complement(const char *complementLabel = nullptr) const;
59 
61  CharacterSet &rename(const char *label) { name = label; return *this; }
62 
64  bool operator == (const CharacterSet &cs) const { return chars_ == cs.chars_; }
66  bool operator != (const CharacterSet &cs) const { return !operator==(cs); }
67 
69  void printChars(std::ostream &os) const;
70 
72  const char * name;
73 
74  // common character sets, RFC 5234
75  // A-Za-z
76  static const CharacterSet ALPHA;
77  // 0-1
78  static const CharacterSet BIT;
79  // carriage return
80  static const CharacterSet CR;
81  // controls
82  static const CharacterSet CTL;
83  // 0-9
84  static const CharacterSet DIGIT;
85  // double quote
86  static const CharacterSet DQUOTE;
87  // 0-9aAbBcCdDeEfF
88  static const CharacterSet HEXDIG;
89  // horizontal tab
90  static const CharacterSet HTAB;
91  // line feed
92  static const CharacterSet LF;
93  // white space
94  static const CharacterSet SP;
95  // visible (printable) characters
96  static const CharacterSet VCHAR;
97  // <space><tab>
98  static const CharacterSet WSP;
99 
100  // HTTP character sets, RFC 7230
101  // ctext
102  static const CharacterSet CTEXT;
103  // XXX: maybe field-vchar = VCHAR / obs-text
104  // any VCHAR except for SPECIAL
105  static const CharacterSet TCHAR;
106  // special VCHARs
107  static const CharacterSet SPECIAL;
108  // qdtext
109  static const CharacterSet QDTEXT;
110  // obs-text
111  static const CharacterSet OBSTEXT;
112 
113  // HTTP character sets, RFC 7232
114  // etagc
115  static const CharacterSet ETAGC;
116 
117  // HTTP character sets, RFC 7235
118  // token68 (internal characters only, excludes '=' terminator)
119  static const CharacterSet TOKEN68C;
120 
121 private:
128 };
129 
136 operator+ (CharacterSet lhs, const CharacterSet &rhs);
137 
144 operator- (CharacterSet lhs, const CharacterSet &rhs);
145 
146 std::ostream&
147 operator <<(std::ostream &, const CharacterSet &);
148 
149 #endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */
150 
const char * name
optional set label for debugging (default: "anonymous")
Definition: CharacterSet.h:72
CharacterSet complement(const char *complementLabel=nullptr) const
Definition: CharacterSet.cc:74
static const CharacterSet CTEXT
Definition: CharacterSet.h:102
static const CharacterSet ETAGC
Definition: CharacterSet.h:115
static const CharacterSet LF
Definition: CharacterSet.h:92
CharacterSet & add(const unsigned char c)
add a given character to the character set
Definition: CharacterSet.cc:47
CharacterSet & operator+=(const CharacterSet &rhs)
set addition: add to this set all characters that are also in rhs
Definition: CharacterSet.cc:17
static const CharacterSet VCHAR
Definition: CharacterSet.h:96
static const CharacterSet ALPHA
Definition: CharacterSet.h:76
static const CharacterSet CR
Definition: CharacterSet.h:80
static const CharacterSet DQUOTE
Definition: CharacterSet.h:86
bool operator!=(const CharacterSet &cs) const
Definition: CharacterSet.h:66
static const CharacterSet WSP
Definition: CharacterSet.h:98
std::vector< uint8_t > Storage
Definition: CharacterSet.h:20
std::ostream & operator<<(std::ostream &, const CharacterSet &)
CharacterSet & addRange(unsigned char low, unsigned char high)
add a list of character ranges, expressed as pairs [low,high], including both ends
Definition: CharacterSet.cc:61
static const CharacterSet TCHAR
Definition: CharacterSet.h:105
static const CharacterSet HEXDIG
Definition: CharacterSet.h:88
CharacterSet & operator-=(const CharacterSet &rhs)
set subtraction: remove all characters that are also in rhs
Definition: CharacterSet.cc:32
static const CharacterSet HTAB
Definition: CharacterSet.h:90
static const CharacterSet SPECIAL
Definition: CharacterSet.h:107
void printChars(std::ostream &os) const
prints all chars in arbitrary order, without any quoting/escaping
static const CharacterSet QDTEXT
Definition: CharacterSet.h:109
static const CharacterSet BIT
Definition: CharacterSet.h:78
static const CharacterSet DIGIT
Definition: CharacterSet.h:84
CharacterSet & rename(const char *label)
change name; handy in const declarations that use operators
Definition: CharacterSet.h:61
bool operator[](unsigned char c) const
whether a given character exists in the set
Definition: CharacterSet.h:39
CharacterSet & remove(const unsigned char c)
remove a given character from the character set
Definition: CharacterSet.cc:54
CharacterSet(const char *label="anonymous", const char *const chars="")
a character set with a given label and contents
Definition: CharacterSet.cc:83
bool operator==(const CharacterSet &cs) const
Definition: CharacterSet.h:64
Storage chars_
Definition: CharacterSet.h:127
static const CharacterSet TOKEN68C
Definition: CharacterSet.h:119
CharacterSet operator+(CharacterSet lhs, const CharacterSet &rhs)
static const CharacterSet CTL
Definition: CharacterSet.h:82
static const CharacterSet OBSTEXT
Definition: CharacterSet.h:111
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:18
CharacterSet operator-(CharacterSet lhs, const CharacterSet &rhs)
bool isEmpty() const
whether the set lacks any members
Definition: CharacterSet.h:36
static const CharacterSet SP
Definition: CharacterSet.h:94

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors