OLD | NEW |
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 const char* ampersand_code; | 330 const char* ampersand_code; |
331 const char replacement; | 331 const char replacement; |
332 } kEscapeToChars[] = { | 332 } kEscapeToChars[] = { |
333 { "<", '<' }, | 333 { "<", '<' }, |
334 { ">", '>' }, | 334 { ">", '>' }, |
335 { "&", '&' }, | 335 { "&", '&' }, |
336 { """, '"' }, | 336 { """, '"' }, |
337 { "'", '\''}, | 337 { "'", '\''}, |
338 }; | 338 }; |
339 | 339 |
340 if (input.find(ASCIIToUTF16("&")) == std::string::npos) | 340 if (input.find(base::ASCIIToUTF16("&")) == std::string::npos) |
341 return input; | 341 return input; |
342 | 342 |
343 base::string16 ampersand_chars[ARRAYSIZE_UNSAFE(kEscapeToChars)]; | 343 base::string16 ampersand_chars[ARRAYSIZE_UNSAFE(kEscapeToChars)]; |
344 base::string16 text(input); | 344 base::string16 text(input); |
345 for (base::string16::iterator iter = text.begin(); | 345 for (base::string16::iterator iter = text.begin(); |
346 iter != text.end(); ++iter) { | 346 iter != text.end(); ++iter) { |
347 if (*iter == '&') { | 347 if (*iter == '&') { |
348 // Potential ampersand encode char. | 348 // Potential ampersand encode char. |
349 size_t index = iter - text.begin(); | 349 size_t index = iter - text.begin(); |
350 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEscapeToChars); i++) { | 350 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEscapeToChars); i++) { |
351 if (ampersand_chars[i].empty()) | 351 if (ampersand_chars[i].empty()) { |
352 ampersand_chars[i] = ASCIIToUTF16(kEscapeToChars[i].ampersand_code); | 352 ampersand_chars[i] = |
| 353 base::ASCIIToUTF16(kEscapeToChars[i].ampersand_code); |
| 354 } |
353 if (text.find(ampersand_chars[i], index) == index) { | 355 if (text.find(ampersand_chars[i], index) == index) { |
354 text.replace(iter, iter + ampersand_chars[i].length(), | 356 text.replace(iter, iter + ampersand_chars[i].length(), |
355 1, kEscapeToChars[i].replacement); | 357 1, kEscapeToChars[i].replacement); |
356 break; | 358 break; |
357 } | 359 } |
358 } | 360 } |
359 } | 361 } |
360 } | 362 } |
361 return text; | 363 return text; |
362 } | 364 } |
(...skipping 20 matching lines...) Expand all Loading... |
383 return; | 385 return; |
384 } | 386 } |
385 adjusted_offset -= 2; | 387 adjusted_offset -= 2; |
386 } | 388 } |
387 offset = adjusted_offset; | 389 offset = adjusted_offset; |
388 } | 390 } |
389 | 391 |
390 } // namespace internal | 392 } // namespace internal |
391 | 393 |
392 } // namespace net | 394 } // namespace net |
OLD | NEW |