]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/CharacterSet.cc
2 * Copyright (C) 1996-2018 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.
10 #include "CharacterSet.h"
17 CharacterSet::operator +=(const CharacterSet
&src
)
19 Storage::const_iterator s
= src
.chars_
.begin();
20 const Storage::const_iterator e
= src
.chars_
.end();
21 Storage::iterator d
= chars_
.begin();
32 CharacterSet::operator -=(const CharacterSet
&src
)
34 Storage::const_iterator s
= src
.chars_
.begin();
35 const Storage::const_iterator e
= src
.chars_
.end();
36 Storage::iterator d
= chars_
.begin();
47 CharacterSet::add(const unsigned char c
)
49 chars_
[static_cast<uint8_t>(c
)] = 1;
54 CharacterSet::addRange(unsigned char low
, unsigned char high
)
56 //manual loop splitting is needed to cover case where high is 255
57 // otherwise low will wrap, resulting in infinite loop
59 chars_
[static_cast<uint8_t>(low
)] = 1;
62 chars_
[static_cast<uint8_t>(high
)] = 1;
67 CharacterSet::complement(const char *label
) const
69 CharacterSet
result((label
? label
: "complement_of_some_other_set"), "");
70 // negate each of our elements and add them to the result storage
71 std::transform(chars_
.begin(), chars_
.end(), result
.chars_
.begin(),
72 std::logical_not
<Storage::value_type
>());
76 CharacterSet::CharacterSet(const char *label
, const char * const c
) :
77 name(label
? label
: "anonymous"),
78 chars_(Storage(256,0))
80 const size_t clen
= strlen(c
);
81 for (size_t i
= 0; i
< clen
; ++i
)
85 CharacterSet::CharacterSet(const char *label
, unsigned char low
, unsigned char high
) :
86 name(label
? label
: "anonymous"),
87 chars_(Storage(256,0))
92 CharacterSet::CharacterSet(const char *label
, std::initializer_list
<std::pair
<uint8_t, uint8_t>> ranges
) :
93 name(label
? label
: "anonymous"),
94 chars_(Storage(256,0))
96 for (auto range
: ranges
)
97 addRange(range
.first
, range
.second
);
101 CharacterSet::printChars(std::ostream
&os
) const
103 for (size_t idx
= 0; idx
< 256; ++idx
) {
105 os
<< static_cast<char>(idx
);
110 operator+ (CharacterSet lhs
, const CharacterSet
&rhs
)
117 operator- (CharacterSet lhs
, const CharacterSet
&rhs
)
124 operator <<(std::ostream
&s
, const CharacterSet
&c
)
126 s
<< "CharacterSet(" << c
.name
<< ')';
132 CharacterSet::ALPHA("ALPHA", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
133 CharacterSet::BIT("BIT","01"),
134 CharacterSet::CR("CR","\r"),
135 CharacterSet::CTL("CTL", {{0x01,0x1f},{0x7f,0x7f}}),
136 CharacterSet::DIGIT("DIGIT","0123456789"),
137 CharacterSet::DQUOTE("DQUOTE","\""),
138 CharacterSet::HEXDIG("HEXDIG","0123456789aAbBcCdDeEfF"),
139 CharacterSet::HTAB("HTAB","\t"),
140 CharacterSet::LF("LF","\n"),
141 CharacterSet::SP("SP"," "),
142 CharacterSet::VCHAR("VCHAR", 0x21, 0x7e),
144 CharacterSet::WSP("WSP"," \t"),
145 CharacterSet::CTEXT("ctext", {{0x09,0x09},{0x20,0x20},{0x2a,0x5b},{0x5d,0x7e},{0x80,0xff}}),
146 CharacterSet::TCHAR("TCHAR","!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
147 CharacterSet::SPECIAL("SPECIAL","()<>@,;:\\\"/[]?={}"),
148 CharacterSet::QDTEXT("QDTEXT", {{0x09,0x09},{0x20,0x21},{0x23,0x5b},{0x5d,0x7e},{0x80,0xff}}),
149 CharacterSet::OBSTEXT("OBSTEXT",0x80,0xff),
151 CharacterSet::ETAGC("ETAGC", {{0x21,0x21},{0x23,0x7e},{0x80,0xff}}),
153 CharacterSet::TOKEN68C("TOKEN68C","-._~+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")