OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 const unsigned char ASCII_CLASS[128] = { | 135 const unsigned char ASCII_CLASS[128] = { |
136 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | 136 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
137 1,0,3,1,1,1,3,2,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,3,1,3,1, | 137 1,0,3,1,1,1,3,2,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,3,1,3,1, |
138 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0, | 138 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0, |
139 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1, | 139 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1, |
140 }; | 140 }; |
141 | 141 |
142 size_t url_encode(char * buffer, size_t buflen, | 142 size_t url_encode(char * buffer, size_t buflen, |
143 const char * source, size_t srclen) { | 143 const char * source, size_t srclen) { |
144 if (NULL == buffer) | 144 if (nullptr == buffer) |
145 return srclen * 3 + 1; | 145 return srclen * 3 + 1; |
146 if (buflen <= 0) | 146 if (buflen <= 0) |
147 return 0; | 147 return 0; |
148 | 148 |
149 size_t srcpos = 0, bufpos = 0; | 149 size_t srcpos = 0, bufpos = 0; |
150 while ((srcpos < srclen) && (bufpos + 1 < buflen)) { | 150 while ((srcpos < srclen) && (bufpos + 1 < buflen)) { |
151 unsigned char ch = source[srcpos++]; | 151 unsigned char ch = source[srcpos++]; |
152 if ((ch < 128) && (ASCII_CLASS[ch] & URL_UNSAFE)) { | 152 if ((ch < 128) && (ASCII_CLASS[ch] & URL_UNSAFE)) { |
153 if (bufpos + 3 >= buflen) { | 153 if (bufpos + 3 >= buflen) { |
154 break; | 154 break; |
155 } | 155 } |
156 buffer[bufpos+0] = '%'; | 156 buffer[bufpos+0] = '%'; |
157 buffer[bufpos+1] = hex_encode((ch >> 4) & 0xF); | 157 buffer[bufpos+1] = hex_encode((ch >> 4) & 0xF); |
158 buffer[bufpos+2] = hex_encode((ch ) & 0xF); | 158 buffer[bufpos+2] = hex_encode((ch ) & 0xF); |
159 bufpos += 3; | 159 bufpos += 3; |
160 } else { | 160 } else { |
161 buffer[bufpos++] = ch; | 161 buffer[bufpos++] = ch; |
162 } | 162 } |
163 } | 163 } |
164 buffer[bufpos] = '\0'; | 164 buffer[bufpos] = '\0'; |
165 return bufpos; | 165 return bufpos; |
166 } | 166 } |
167 | 167 |
168 size_t url_decode(char * buffer, size_t buflen, | 168 size_t url_decode(char * buffer, size_t buflen, |
169 const char * source, size_t srclen) { | 169 const char * source, size_t srclen) { |
170 if (NULL == buffer) | 170 if (nullptr == buffer) |
171 return srclen + 1; | 171 return srclen + 1; |
172 if (buflen <= 0) | 172 if (buflen <= 0) |
173 return 0; | 173 return 0; |
174 | 174 |
175 unsigned char h1, h2; | 175 unsigned char h1, h2; |
176 size_t srcpos = 0, bufpos = 0; | 176 size_t srcpos = 0, bufpos = 0; |
177 while ((srcpos < srclen) && (bufpos + 1 < buflen)) { | 177 while ((srcpos < srclen) && (bufpos + 1 < buflen)) { |
178 unsigned char ch = source[srcpos++]; | 178 unsigned char ch = source[srcpos++]; |
179 if (ch == '+') { | 179 if (ch == '+') { |
180 buffer[bufpos++] = ' '; | 180 buffer[bufpos++] = ' '; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 size_t transform(std::string& value, size_t maxlen, const std::string& source, | 539 size_t transform(std::string& value, size_t maxlen, const std::string& source, |
540 Transform t) { | 540 Transform t) { |
541 char* buffer = STACK_ARRAY(char, maxlen + 1); | 541 char* buffer = STACK_ARRAY(char, maxlen + 1); |
542 size_t length = t(buffer, maxlen + 1, source.data(), source.length()); | 542 size_t length = t(buffer, maxlen + 1, source.data(), source.length()); |
543 value.assign(buffer, length); | 543 value.assign(buffer, length); |
544 return length; | 544 return length; |
545 } | 545 } |
546 | 546 |
547 std::string s_transform(const std::string& source, Transform t) { | 547 std::string s_transform(const std::string& source, Transform t) { |
548 // Ask transformation function to approximate the destination size (returns up
per bound) | 548 // Ask transformation function to approximate the destination size (returns up
per bound) |
549 size_t maxlen = t(NULL, 0, source.data(), source.length()); | 549 size_t maxlen = t(nullptr, 0, source.data(), source.length()); |
550 char * buffer = STACK_ARRAY(char, maxlen); | 550 char * buffer = STACK_ARRAY(char, maxlen); |
551 size_t len = t(buffer, maxlen, source.data(), source.length()); | 551 size_t len = t(buffer, maxlen, source.data(), source.length()); |
552 std::string result(buffer, len); | 552 std::string result(buffer, len); |
553 return result; | 553 return result; |
554 } | 554 } |
555 | 555 |
556 size_t tokenize(const std::string& source, char delimiter, | 556 size_t tokenize(const std::string& source, char delimiter, |
557 std::vector<std::string>* fields) { | 557 std::vector<std::string>* fields) { |
558 fields->clear(); | 558 fields->clear(); |
559 size_t last = 0; | 559 size_t last = 0; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 va_list args; | 687 va_list args; |
688 va_start(args, format); | 688 va_start(args, format); |
689 value.assign(buffer, vsprintfn(buffer, maxlen + 1, format, args)); | 689 value.assign(buffer, vsprintfn(buffer, maxlen + 1, format, args)); |
690 va_end(args); | 690 va_end(args); |
691 } | 691 } |
692 */ | 692 */ |
693 | 693 |
694 ///////////////////////////////////////////////////////////////////////////// | 694 ///////////////////////////////////////////////////////////////////////////// |
695 | 695 |
696 } // namespace rtc | 696 } // namespace rtc |
OLD | NEW |