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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const Charmap& charmap, | 45 const Charmap& charmap, |
46 bool use_plus, | 46 bool use_plus, |
47 bool keep_escaped = false) { | 47 bool keep_escaped = false) { |
48 std::string escaped; | 48 std::string escaped; |
49 escaped.reserve(text.length() * 3); | 49 escaped.reserve(text.length() * 3); |
50 for (unsigned int i = 0; i < text.length(); ++i) { | 50 for (unsigned int i = 0; i < text.length(); ++i) { |
51 unsigned char c = static_cast<unsigned char>(text[i]); | 51 unsigned char c = static_cast<unsigned char>(text[i]); |
52 if (use_plus && ' ' == c) { | 52 if (use_plus && ' ' == c) { |
53 escaped.push_back('+'); | 53 escaped.push_back('+'); |
54 } else if (keep_escaped && '%' == c && i + 2 < text.length() && | 54 } else if (keep_escaped && '%' == c && i + 2 < text.length() && |
55 IsHexDigit(text[i + 1]) && IsHexDigit(text[i + 2])) { | 55 base::IsHexDigit(text[i + 1]) && base::IsHexDigit(text[i + 2])) { |
56 escaped.push_back('%'); | 56 escaped.push_back('%'); |
57 } else if (charmap.Contains(c)) { | 57 } else if (charmap.Contains(c)) { |
58 escaped.push_back('%'); | 58 escaped.push_back('%'); |
59 escaped.push_back(IntToHex(c >> 4)); | 59 escaped.push_back(IntToHex(c >> 4)); |
60 escaped.push_back(IntToHex(c & 0xf)); | 60 escaped.push_back(IntToHex(c & 0xf)); |
61 } else { | 61 } else { |
62 escaped.push_back(c); | 62 escaped.push_back(c); |
63 } | 63 } |
64 } | 64 } |
65 return escaped; | 65 return escaped; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 size_t index, | 111 size_t index, |
112 unsigned char* value) { | 112 unsigned char* value) { |
113 if ((index + 2) >= escaped_text.size()) | 113 if ((index + 2) >= escaped_text.size()) |
114 return false; | 114 return false; |
115 if (escaped_text[index] != '%') | 115 if (escaped_text[index] != '%') |
116 return false; | 116 return false; |
117 const typename STR::value_type most_sig_digit( | 117 const typename STR::value_type most_sig_digit( |
118 static_cast<typename STR::value_type>(escaped_text[index + 1])); | 118 static_cast<typename STR::value_type>(escaped_text[index + 1])); |
119 const typename STR::value_type least_sig_digit( | 119 const typename STR::value_type least_sig_digit( |
120 static_cast<typename STR::value_type>(escaped_text[index + 2])); | 120 static_cast<typename STR::value_type>(escaped_text[index + 2])); |
121 if (IsHexDigit(most_sig_digit) && IsHexDigit(least_sig_digit)) { | 121 if (base::IsHexDigit(most_sig_digit) && base::IsHexDigit(least_sig_digit)) { |
122 *value = HexDigitToInt(most_sig_digit) * 16 + | 122 *value = base::HexDigitToInt(most_sig_digit) * 16 + |
123 HexDigitToInt(least_sig_digit); | 123 base::HexDigitToInt(least_sig_digit); |
124 return true; | 124 return true; |
125 } | 125 } |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
129 // Returns true if there is an Arabic Language Mark at |index|. |first_byte| | 129 // Returns true if there is an Arabic Language Mark at |index|. |first_byte| |
130 // is the byte at |index|. | 130 // is the byte at |index|. |
131 template<typename STR> | 131 template<typename STR> |
132 bool HasArabicLanguageMarkAtIndex(const STR& escaped_text, | 132 bool HasArabicLanguageMarkAtIndex(const STR& escaped_text, |
133 unsigned char first_byte, | 133 unsigned char first_byte, |
(...skipping 320 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 |