]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
c8046ec7 | 9 | #include "squid.h" |
c8046ec7 FC |
10 | #include "CharacterSet.h" |
11 | ||
b5cb2dbf AR |
12 | #include <algorithm> |
13 | #include <functional> | |
14 | ||
18538c13 | 15 | CharacterSet & |
c8046ec7 FC |
16 | CharacterSet::operator +=(const CharacterSet &src) |
17 | { | |
d27140db FC |
18 | Storage::const_iterator s = src.chars_.begin(); |
19 | const Storage::const_iterator e = src.chars_.end(); | |
20 | Storage::iterator d = chars_.begin(); | |
21 | while (s != e) { | |
22 | if (*s) | |
23 | *d = 1; | |
24 | ++s; | |
25 | ++d; | |
26 | } | |
c8046ec7 FC |
27 | return *this; |
28 | } | |
dcd4fdac | 29 | |
18538c13 FC |
30 | CharacterSet |
31 | CharacterSet::operator +(const CharacterSet &src) const | |
32 | { | |
33 | CharacterSet rv(*this); | |
34 | rv += src; | |
35 | return rv; | |
36 | } | |
37 | ||
dcd4fdac FC |
38 | CharacterSet & |
39 | CharacterSet::add(const unsigned char c) | |
40 | { | |
41 | chars_[static_cast<uint8_t>(c)] = 1; | |
42 | return *this; | |
43 | } | |
44 | ||
18538c13 | 45 | CharacterSet & |
decd2fc6 | 46 | CharacterSet::addRange(unsigned char low, unsigned char high) |
18538c13 | 47 | { |
d26d8af4 FC |
48 | //manual loop splitting is needed to cover case where high is 255 |
49 | // otherwise low will wrap, resulting in infinite loop | |
50 | while (low < high) { | |
decd2fc6 FC |
51 | chars_[static_cast<uint8_t>(low)] = 1; |
52 | ++low; | |
18538c13 | 53 | } |
d26d8af4 | 54 | chars_[static_cast<uint8_t>(high)] = 1; |
18538c13 FC |
55 | return *this; |
56 | } | |
57 | ||
b5cb2dbf AR |
58 | CharacterSet |
59 | CharacterSet::complement(const char *label) const | |
60 | { | |
61 | CharacterSet result((label ? label : "complement_of_some_other_set"), ""); | |
62 | // negate each of our elements and add them to the result storage | |
63 | std::transform(chars_.begin(), chars_.end(), result.chars_.begin(), | |
64 | std::logical_not<Storage::value_type>()); | |
65 | return result; | |
66 | } | |
67 | ||
86c63190 | 68 | CharacterSet::CharacterSet(const char *label, const char * const c) : |
f53969cc SM |
69 | name(label == NULL ? "anonymous" : label), |
70 | chars_(Storage(256,0)) | |
dcd4fdac FC |
71 | { |
72 | const size_t clen = strlen(c); | |
73 | for (size_t i = 0; i < clen; ++i) | |
74 | add(c[i]); | |
75 | } | |
18538c13 | 76 | |
86c63190 | 77 | CharacterSet::CharacterSet(const char *label, unsigned char low, unsigned char high) : |
f53969cc SM |
78 | name(label == NULL ? "anonymous" : label), |
79 | chars_(Storage(256,0)) | |
8664ceb4 | 80 | { |
decd2fc6 | 81 | addRange(low,high); |
8664ceb4 FC |
82 | } |
83 | ||
18538c13 | 84 | const CharacterSet |
98b721ce | 85 | // RFC 5234 |
decd2fc6 | 86 | CharacterSet::ALPHA("ALPHA", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), |
f53969cc SM |
87 | CharacterSet::BIT("BIT","01"), |
88 | CharacterSet::CR("CR","\r"), | |
98b721ce AJ |
89 | #if __cplusplus == 201103L |
90 | //CharacterSet::CTL("CTL",{{0x01,0x1f},{0x7f,0x7f}}), | |
91 | #endif | |
f53969cc SM |
92 | CharacterSet::DIGIT("DIGIT","0123456789"), |
93 | CharacterSet::DQUOTE("DQUOTE","\""), | |
94 | CharacterSet::HEXDIG("HEXDIG","0123456789aAbBcCdDeEfF"), | |
95 | CharacterSet::HTAB("HTAB","\t"), | |
96 | CharacterSet::LF("LF","\n"), | |
97 | CharacterSet::SP("SP"," "), | |
98 | CharacterSet::VCHAR("VCHAR", 0x21, 0x7e), | |
98b721ce | 99 | // RFC 7230 |
f53969cc | 100 | CharacterSet::WSP("WSP"," \t"), |
98b721ce AJ |
101 | #if __cplusplus == 201103L |
102 | //CharacterSet::CTEXT("ctext",{{0x09,0x09},{0x20,0x20},{0x2a,0x5b},{0x5d,0x7e},{0x80,0xff}}), | |
103 | #endif | |
f53969cc SM |
104 | CharacterSet::TCHAR("TCHAR","!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), |
105 | CharacterSet::SPECIAL("SPECIAL","()<>@,;:\\\"/[]?={}"), | |
98b721ce AJ |
106 | #if __cplusplus == 201103L |
107 | //CharacterSet::QDTEXT("QDTEXT",{{0x09,0x09},{0x20,0x21},{0x23,0x5b},{0x5d,0x7e},{0x80,0xff}}), | |
108 | #endif | |
f53969cc | 109 | CharacterSet::OBSTEXT("OBSTEXT",0x80,0xff), |
98b721ce AJ |
110 | // RFC 7232 |
111 | #if __cplusplus == 201103L | |
112 | //CharacterSet::ETAGC("ETAGC",{{0x21,0x21},{0x23,0x7e},{0x80,0xff}}), | |
113 | #endif | |
114 | // RFC 7235 | |
f53969cc SM |
115 | CharacterSet::TOKEN68C("TOKEN68C","-._~+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
116 | ; | |
117 |