]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/CharacterSet.h
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef _SQUID_SRC_PARSER_CHARACTERSET_H
10 #define _SQUID_SRC_PARSER_CHARACTERSET_H
14 /// optimized set of C chars, with quick membership test and merge support
18 typedef std::vector
<uint8_t> Storage
;
20 /// define a character set with the given label ("anonymous" if NULL)
21 /// with specified initial contents
22 CharacterSet(const char *label
, const char * const initial
);
24 /// define a character set with the given label ("anonymous" if NULL)
25 /// containing characters defined in the supplied ranges
27 CharacterSet(const char *label
, unsigned char low
, unsigned char high
);
29 /// whether a given character exists in the set
30 bool operator[](unsigned char c
) const {return chars_
[static_cast<uint8_t>(c
)] != 0;}
32 /// add a given character to the character set
33 CharacterSet
& add(const unsigned char c
);
35 /// add a list of character ranges, expressed as pairs [low,high], including both ends
36 CharacterSet
& addRange(unsigned char low
, unsigned char high
);
38 /// add all characters from the given CharacterSet to this one
39 CharacterSet
&operator +=(const CharacterSet
&src
);
41 /// return a new CharacterSet containing the union of two sets
42 CharacterSet
operator +(const CharacterSet
&src
) const;
44 /// return a new CharacterSet containing characters not in this set
45 CharacterSet
complement(const char *complementLabel
= NULL
) const;
47 /// change name; handy in const declarations that use operators
48 CharacterSet
&rename(const char *label
) { name
= label
; return *this; }
50 /// optional set label for debugging (default: "anonymous")
53 // common character sets, RFC 5234
55 static const CharacterSet ALPHA
;
57 static const CharacterSet BIT
;
59 static const CharacterSet CR
;
61 #if __cplusplus == 201103L
62 // ready but disabled as needs C++11 constructor
63 //static const CharacterSet CTL;
66 static const CharacterSet DIGIT
;
68 static const CharacterSet DQUOTE
;
70 static const CharacterSet HEXDIG
;
72 static const CharacterSet HTAB
;
74 static const CharacterSet LF
;
76 static const CharacterSet SP
;
77 // visible (printable) characters
78 static const CharacterSet VCHAR
;
80 static const CharacterSet WSP
;
82 // HTTP character sets, RFC 7230
84 #if __cplusplus == 201103L
85 // ready but disabled as needs C++11 constructor
86 //static const CharacterSet CTEXT;
88 // XXX: maybe field-vchar = VCHAR / obs-text
89 // any VCHAR except for SPECIAL
90 static const CharacterSet TCHAR
;
92 static const CharacterSet SPECIAL
;
94 #if __cplusplus == 201103L
95 // ready but disabled as needs C++11 constructor
96 //static const CharacterSet QDTEXT;
99 static const CharacterSet OBSTEXT
;
101 // HTTP character sets, RFC 7232
103 #if __cplusplus == 201103L
104 // ready but disabled as needs C++11 constructor
105 //static const CharacterSet ETAGC;
108 // HTTP character sets, RFC 7235
109 // token68 (internal charaters only, excludes '=' terminator)
110 static const CharacterSet TOKEN68C
;
113 /** index of characters in this set
115 * \note guaranteed to be always 256 slots big, as forced in the
116 * constructor. This assumption is relied upon in operator[], add,
122 #endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */