37 const std::string& description,
38 const std::string& defaultValue) {
41 if (defaultValue ==
"None") {
42 opt->fAddToRange(defaultValue);
51 const char* ueChars =
"0123456789.-~_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
52 for (
const char *c = ueChars; *c; c++) {
61 void escape(
const std::string& unEscaped, std::string& escaped)
const override {
62 for (
auto c : unEscaped) {
66 static const char hexEncode[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
67 escaped.push_back(
'%');
69 escaped.push_back(hexEncode[ (c >> 4) & 0x0F ]);
70 escaped.push_back(hexEncode[ c & 0x0F ]);
74 void deEscape(
const std::string& escaped, std::string& unEscaped)
const override {
75 unEscaped.reserve(escaped.size());
76 std::remove_reference<decltype(unEscaped)>::type::value_type code;
77 enum {normal, firstNibble, secondNibble} state = normal;
78 for (
auto c : escaped) {
79 if (state == normal) {
84 unEscaped.push_back(c);
86 decltype(code) nibble;
87 if (std::isdigit(c)) {
91 if (
'A' <= c && c <=
'F') {
92 nibble = c -
'A' + 10;
94 throw std::invalid_argument(
"bad encoding");
97 if (state == firstNibble) {
103 unEscaped.push_back(code);
110 if (state != normal) {
111 throw std::invalid_argument(
"bad encoding");
122 const char* ueChars =
"0123456789.-~_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/";
123 for (
const char *c = ueChars; *c; c++) {
126 return codingPattern;
140 static std::remove_reference<decltype(
getEscapeMap())>::type escapeMap{
155 std::map<char, char> map;
157 map.emplace(item.second, item.first);
168 for (
char c =
' '; c < 127; c++) {
173 return codingPattern;
179 void escape(
const std::string& unEscaped, std::string& escaped)
const override {
180 for (
auto c : unEscaped) {
182 escaped.push_back(c);
184 escaped.push_back(
'\\');
187 escaped.push_back(enc->second);
189 escaped.push_back(
'0' + ((c >> 6) & 0x07));
190 escaped.push_back(
'0' + ((c >> 3) & 0x07));
191 escaped.push_back(
'0' + ((c >> 0) & 0x07));
196 void deEscape(
const std::string& escaped, std::string& unEscaped)
const override {
197 unEscaped.reserve(escaped.size());
198 std::remove_reference<decltype(unEscaped)>::type::value_type code;
199 enum {normal, escaping, second3bits, last3bits} state = normal;
200 for (
auto c : escaped) {
201 if (state == normal) {
206 unEscaped.push_back(c);
207 }
else if (state == escaping) {
210 unEscaped.push_back(enc->second);
214 if (
'0' <= c && c <=
'7') {
215 decltype(code) threeBits;
217 code = threeBits << 6;
221 throw std::invalid_argument(
"bad encoding");
223 }
else if (state == second3bits) {
224 if (
'0' <= c && c <=
'7') {
225 decltype(code) threeBits;
227 code |= threeBits << 3;
231 throw std::invalid_argument(
"bad encoding");
233 }
else if (state == last3bits) {
234 if (
'0' <= c && c <=
'7') {
235 decltype(code) threeBits;
237 code |= threeBits << 0;
238 unEscaped.push_back(code);
242 throw std::invalid_argument(
"bad encoding");
247 if (state != normal) {
248 throw std::invalid_argument(
"bad encoding");