| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // A fast bit-vector map for ascii characters. | 27 // A fast bit-vector map for ascii characters. |
| 28 // | 28 // |
| 29 // Internally stores 256 bits in an array of 8 ints. | 29 // Internally stores 256 bits in an array of 8 ints. |
| 30 // Does quick bit-flicking to lookup needed characters. | 30 // Does quick bit-flicking to lookup needed characters. |
| 31 struct Charmap { | 31 struct Charmap { |
| 32 bool Contains(unsigned char c) const { | 32 bool Contains(unsigned char c) const { |
| 33 return ((map[c >> 5] & (1 << (c & 31))) != 0); | 33 return ((map[c >> 5] & (1 << (c & 31))) != 0); |
| 34 } | 34 } |
| 35 | 35 |
| 36 uint32 map[8]; | 36 uint32_t map[8]; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Given text to escape and a Charmap defining which values to escape, | 39 // Given text to escape and a Charmap defining which values to escape, |
| 40 // return an escaped string. If use_plus is true, spaces are converted | 40 // return an escaped string. If use_plus is true, spaces are converted |
| 41 // to +, otherwise, if spaces are in the charmap, they are converted to | 41 // to +, otherwise, if spaces are in the charmap, they are converted to |
| 42 // %20. And if keep_escaped is true, %XX will be kept as it is, otherwise, if | 42 // %20. And if keep_escaped is true, %XX will be kept as it is, otherwise, if |
| 43 // '%' is in the charmap, it is converted to %25. | 43 // '%' is in the charmap, it is converted to %25. |
| 44 std::string Escape(const std::string& text, | 44 std::string Escape(const std::string& text, |
| 45 const Charmap& charmap, | 45 const Charmap& charmap, |
| 46 bool use_plus, | 46 bool use_plus, |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 1, kEscapeToChars[i].replacement); | 454 1, kEscapeToChars[i].replacement); |
| 455 break; | 455 break; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 return text; | 460 return text; |
| 461 } | 461 } |
| 462 | 462 |
| 463 } // namespace net | 463 } // namespace net |
| OLD | NEW |