]>
Commit | Line | Data |
---|---|---|
3c1106a0 FC |
1 | #ifndef _SQUID_SRC_PARSER_CHARACTERSET_H |
2 | #define _SQUID_SRC_PARSER_CHARACTERSET_H | |
3 | ||
4 | #include <vector> | |
5 | ||
6 | class CharacterSet | |
7 | { | |
8 | public: | |
9 | CharacterSet(const char *label, const char * const c) : name(label), chars_(std::vector<bool>(256,false)) { | |
10 | size_t clen = strlen(c); | |
11 | for (size_t i = 0; i < clen; ++i) | |
12 | chars_[static_cast<uint8_t>(c[i])] = true; | |
13 | } | |
14 | ||
15 | /// whether a given character exists in the set | |
16 | bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)];} | |
17 | ||
18 | /// add a given char to the character set. c must be >= 0. | |
19 | CharacterSet & add(const unsigned char c) {chars_[static_cast<uint8_t>(c)] = true; return *this; } | |
20 | ||
21 | /// add all characters from the given CharacterSet to this one | |
22 | const CharacterSet &operator +=(const CharacterSet &src) { | |
23 | //precondition: src.chars_.size() == chars_.size() | |
24 | std::vector<bool>::const_iterator s = src.chars_.begin(); | |
25 | const std::vector<bool>::const_iterator e = src.chars_.end(); | |
26 | std::vector<bool>::iterator d = chars_.begin(); | |
27 | while (s != e) { | |
28 | if (*s) | |
29 | *d = true; | |
30 | ++s; | |
31 | ++d; | |
32 | } | |
33 | return *this; | |
34 | } | |
35 | ||
36 | /// name of this character set | |
37 | const char * name; | |
38 | ||
39 | private: | |
40 | /// characters defined in this set | |
41 | std::vector<bool> chars_; //std::vector<bool> is optimized | |
42 | }; | |
43 | ||
44 | #endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */ |