CharacterSet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 & addRange(unsigned char low, unsigned char high);
46 
49 
52 
55  CharacterSet complement(const char *complementLabel = nullptr) const;
56 
58  CharacterSet &rename(const char *label) { name = label; return *this; }
59 
61  bool operator == (const CharacterSet &cs) const { return chars_ == cs.chars_; }
63  bool operator != (const CharacterSet &cs) const { return !operator==(cs); }
64 
66  void printChars(std::ostream &os) const;
67 
69  const char * name;
70 
71  // common character sets, RFC 5234
72  // A-Za-z
73  static const CharacterSet ALPHA;
74  // 0-1
75  static const CharacterSet BIT;
76  // carriage return
77  static const CharacterSet CR;
78  // controls
79  static const CharacterSet CTL;
80  // 0-9
81  static const CharacterSet DIGIT;
82  // double quote
83  static const CharacterSet DQUOTE;
84  // 0-9aAbBcCdDeEfF
85  static const CharacterSet HEXDIG;
86  // horizontal tab
87  static const CharacterSet HTAB;
88  // line feed
89  static const CharacterSet LF;
90  // white space
91  static const CharacterSet SP;
92  // visible (printable) characters
93  static const CharacterSet VCHAR;
94  // <space><tab>
95  static const CharacterSet WSP;
96 
97  // HTTP character sets, RFC 7230
98  // ctext
99  static const CharacterSet CTEXT;
100  // XXX: maybe field-vchar = VCHAR / obs-text
101  // any VCHAR except for SPECIAL
102  static const CharacterSet TCHAR;
103  // special VCHARs
104  static const CharacterSet SPECIAL;
105  // qdtext
106  static const CharacterSet QDTEXT;
107  // obs-text
108  static const CharacterSet OBSTEXT;
109 
110  // HTTP character sets, RFC 7232
111  // etagc
112  static const CharacterSet ETAGC;
113 
114  // HTTP character sets, RFC 7235
115  // token68 (internal charaters only, excludes '=' terminator)
116  static const CharacterSet TOKEN68C;
117 
118 private:
125 };
126 
133 operator+ (CharacterSet lhs, const CharacterSet &rhs);
134 
141 operator- (CharacterSet lhs, const CharacterSet &rhs);
142 
143 std::ostream&
144 operator <<(std::ostream &, const CharacterSet &);
145 
146 #endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */
147 
const char * name
optional set label for debugging (default: "anonymous")
Definition: CharacterSet.h:69
void printChars(std::ostream &os) const
prints all chars in arbitrary order, without any quoting/escaping
bool operator!=(const CharacterSet &cs) const
Definition: CharacterSet.h:63
static const CharacterSet LF
Definition: CharacterSet.h:89
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 ETAGC
Definition: CharacterSet.h:112
static const CharacterSet DQUOTE
Definition: CharacterSet.h:83
static const CharacterSet CTEXT
Definition: CharacterSet.h:99
bool operator==(const CharacterSet &cs) const
Definition: CharacterSet.h:61
static const CharacterSet ALPHA
Definition: CharacterSet.h:73
CharacterSet operator+(CharacterSet lhs, const CharacterSet &rhs)
static const CharacterSet TCHAR
Definition: CharacterSet.h:102
static const CharacterSet HEXDIG
Definition: CharacterSet.h:85
CharacterSet & add(const unsigned char c)
add a given character to the character set
Definition: CharacterSet.cc:47
static const CharacterSet WSP
Definition: CharacterSet.h:95
static const CharacterSet VCHAR
Definition: CharacterSet.h:93
std::ostream & operator<<(std::ostream &, const CharacterSet &)
static const CharacterSet DIGIT
Definition: CharacterSet.h:81
std::vector< uint8_t > Storage
Definition: CharacterSet.h:20
bool operator[](unsigned char c) const
whether a given character exists in the set
Definition: CharacterSet.h:39
static const CharacterSet HTAB
Definition: CharacterSet.h:87
static const CharacterSet CR
Definition: CharacterSet.h:77
static const CharacterSet SPECIAL
Definition: CharacterSet.h:104
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
bool isEmpty() const
whether the set lacks any members
Definition: CharacterSet.h:36
CharacterSet & operator-=(const CharacterSet &rhs)
set subtraction: remove all characters that are also in rhs
Definition: CharacterSet.cc:32
Storage chars_
Definition: CharacterSet.h:124
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:54
CharacterSet & rename(const char *label)
change name; handy in const declarations that use operators
Definition: CharacterSet.h:58
static const CharacterSet QDTEXT
Definition: CharacterSet.h:106
static const CharacterSet BIT
Definition: CharacterSet.h:75
static const CharacterSet SP
Definition: CharacterSet.h:91
static const CharacterSet CTL
Definition: CharacterSet.h:79
static const CharacterSet OBSTEXT
Definition: CharacterSet.h:108
CharacterSet complement(const char *complementLabel=nullptr) const
Definition: CharacterSet.cc:67
CharacterSet(const char *label="anonymous", const char *const chars="")
a character set with a given label and contents
Definition: CharacterSet.cc:76
static const CharacterSet TOKEN68C
Definition: CharacterSet.h:116
CharacterSet operator-(CharacterSet lhs, const CharacterSet &rhs)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors