Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: net/base/escape.cc

Issue 662553002: Convert ARRAYSIZE_UNSAFE -> arraysize in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/address_list_unittest.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/escape.h" 5 #include "net/base/escape.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 char key; 237 char key;
238 const char* replacement; 238 const char* replacement;
239 } kCharsToEscape[] = { 239 } kCharsToEscape[] = {
240 { '<', "&lt;" }, 240 { '<', "&lt;" },
241 { '>', "&gt;" }, 241 { '>', "&gt;" },
242 { '&', "&amp;" }, 242 { '&', "&amp;" },
243 { '"', "&quot;" }, 243 { '"', "&quot;" },
244 { '\'', "&#39;" }, 244 { '\'', "&#39;" },
245 }; 245 };
246 size_t k; 246 size_t k;
247 for (k = 0; k < ARRAYSIZE_UNSAFE(kCharsToEscape); ++k) { 247 for (k = 0; k < arraysize(kCharsToEscape); ++k) {
248 if (c == kCharsToEscape[k].key) { 248 if (c == kCharsToEscape[k].key) {
249 const char* p = kCharsToEscape[k].replacement; 249 const char* p = kCharsToEscape[k].replacement;
250 while (*p) 250 while (*p)
251 output->push_back(*p++); 251 output->push_back(*p++);
252 break; 252 break;
253 } 253 }
254 } 254 }
255 if (k == ARRAYSIZE_UNSAFE(kCharsToEscape)) 255 if (k == arraysize(kCharsToEscape))
256 output->push_back(c); 256 output->push_back(c);
257 } 257 }
258 258
259 template <class str> 259 template <class str>
260 str EscapeForHTMLImpl(const str& input) { 260 str EscapeForHTMLImpl(const str& input) {
261 str result; 261 str result;
262 result.reserve(input.size()); // Optimize for no escaping. 262 result.reserve(input.size()); // Optimize for no escaping.
263 263
264 for (typename str::const_iterator i = input.begin(); i != input.end(); ++i) 264 for (typename str::const_iterator i = input.begin(); i != input.end(); ++i)
265 AppendEscapedCharForHTMLImpl(*i, &result); 265 AppendEscapedCharForHTMLImpl(*i, &result);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 { "&lt;", '<' }, 378 { "&lt;", '<' },
379 { "&gt;", '>' }, 379 { "&gt;", '>' },
380 { "&amp;", '&' }, 380 { "&amp;", '&' },
381 { "&quot;", '"' }, 381 { "&quot;", '"' },
382 { "&#39;", '\''}, 382 { "&#39;", '\''},
383 }; 383 };
384 384
385 if (input.find(base::ASCIIToUTF16("&")) == std::string::npos) 385 if (input.find(base::ASCIIToUTF16("&")) == std::string::npos)
386 return input; 386 return input;
387 387
388 base::string16 ampersand_chars[ARRAYSIZE_UNSAFE(kEscapeToChars)]; 388 base::string16 ampersand_chars[arraysize(kEscapeToChars)];
389 base::string16 text(input); 389 base::string16 text(input);
390 for (base::string16::iterator iter = text.begin(); 390 for (base::string16::iterator iter = text.begin();
391 iter != text.end(); ++iter) { 391 iter != text.end(); ++iter) {
392 if (*iter == '&') { 392 if (*iter == '&') {
393 // Potential ampersand encode char. 393 // Potential ampersand encode char.
394 size_t index = iter - text.begin(); 394 size_t index = iter - text.begin();
395 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEscapeToChars); i++) { 395 for (size_t i = 0; i < arraysize(kEscapeToChars); i++) {
396 if (ampersand_chars[i].empty()) { 396 if (ampersand_chars[i].empty()) {
397 ampersand_chars[i] = 397 ampersand_chars[i] =
398 base::ASCIIToUTF16(kEscapeToChars[i].ampersand_code); 398 base::ASCIIToUTF16(kEscapeToChars[i].ampersand_code);
399 } 399 }
400 if (text.find(ampersand_chars[i], index) == index) { 400 if (text.find(ampersand_chars[i], index) == index) {
401 text.replace(iter, iter + ampersand_chars[i].length(), 401 text.replace(iter, iter + ampersand_chars[i].length(),
402 1, kEscapeToChars[i].replacement); 402 1, kEscapeToChars[i].replacement);
403 break; 403 break;
404 } 404 }
405 } 405 }
406 } 406 }
407 } 407 }
408 return text; 408 return text;
409 } 409 }
410 410
411 } // namespace net 411 } // namespace net
OLDNEW
« no previous file with comments | « net/base/address_list_unittest.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698