OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "net/base/escape.h" | 7 #include "net/base/escape.h" |
8 | 8 |
9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // alphanumerics and !'()*-._~ | 245 // alphanumerics and !'()*-._~ |
246 escaped->assign(UTF8ToWide(Escape(encoded, kQueryCharmap, true))); | 246 escaped->assign(UTF8ToWide(Escape(encoded, kQueryCharmap, true))); |
247 return true; | 247 return true; |
248 } | 248 } |
249 | 249 |
250 std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text, | 250 std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text, |
251 UnescapeRule::Type rules, | 251 UnescapeRule::Type rules, |
252 size_t* offset_for_adjustment) { | 252 size_t* offset_for_adjustment) { |
253 std::wstring result; | 253 std::wstring result; |
254 size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0; | 254 size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0; |
255 if (base::CodepageToWideAndAdjustOffset( | 255 std::string unescaped_url( |
256 UnescapeURLImpl(text, rules, offset_for_adjustment), | 256 UnescapeURLImpl(text, rules, offset_for_adjustment)); |
257 "UTF-8", base::OnStringConversionError::FAIL, &result, | 257 if (UTF8ToWideAndAdjustOffset(unescaped_url.data(), unescaped_url.length(), |
258 offset_for_adjustment)) | 258 &result, offset_for_adjustment)) |
259 return result; // Character set looks like it's valid. | 259 return result; // Character set looks like it's valid. |
260 | 260 |
261 // Not valid. Return the escaped version. Undo our changes to | 261 // Not valid. Return the escaped version. Undo our changes to |
262 // |offset_for_adjustment| since we haven't changed the string after all. | 262 // |offset_for_adjustment| since we haven't changed the string after all. |
263 if (offset_for_adjustment) | 263 if (offset_for_adjustment) |
264 *offset_for_adjustment = original_offset; | 264 *offset_for_adjustment = original_offset; |
265 return UTF8ToWideAndAdjustOffset(text, offset_for_adjustment); | 265 return UTF8ToWideAndAdjustOffset(text, offset_for_adjustment); |
266 } | 266 } |
267 | 267 |
268 std::string UnescapeURLComponent(const std::string& escaped_text, | 268 std::string UnescapeURLComponent(const std::string& escaped_text, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return result; | 314 return result; |
315 } | 315 } |
316 | 316 |
317 std::string EscapeForHTML(const std::string& input) { | 317 std::string EscapeForHTML(const std::string& input) { |
318 return EscapeForHTMLImpl(input); | 318 return EscapeForHTMLImpl(input); |
319 } | 319 } |
320 | 320 |
321 std::wstring EscapeForHTML(const std::wstring& input) { | 321 std::wstring EscapeForHTML(const std::wstring& input) { |
322 return EscapeForHTMLImpl(input); | 322 return EscapeForHTMLImpl(input); |
323 } | 323 } |
OLD | NEW |