| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_ESCAPE_H__ | 5 #ifndef NET_BASE_ESCAPE_H__ |
| 6 #define NET_BASE_ESCAPE_H__ | 6 #define NET_BASE_ESCAPE_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // | 86 // |
| 87 // Watch out: this doesn't necessarily result in the correct final result, | 87 // Watch out: this doesn't necessarily result in the correct final result, |
| 88 // because the encoding may be unknown. For example, the input might be ASCII, | 88 // because the encoding may be unknown. For example, the input might be ASCII, |
| 89 // which, after unescaping, is supposed to be interpreted as UTF-8, and then | 89 // which, after unescaping, is supposed to be interpreted as UTF-8, and then |
| 90 // converted into full wide chars. This function won't tell you if any | 90 // converted into full wide chars. This function won't tell you if any |
| 91 // conversions need to take place, it only unescapes. | 91 // conversions need to take place, it only unescapes. |
| 92 std::string UnescapeURLComponent(const std::string& escaped_text, | 92 std::string UnescapeURLComponent(const std::string& escaped_text, |
| 93 UnescapeRule::Type rules); | 93 UnescapeRule::Type rules); |
| 94 | 94 |
| 95 // Unescapes the given substring as a URL, and then tries to interpret the | 95 // Unescapes the given substring as a URL, and then tries to interpret the |
| 96 // result as being encoded in the given code page. If the result is convertable | 96 // result as being encoded as UTF-8. If the result is convertable into UTF-8, it |
| 97 // into the code page, it will be returned as converted. If it is not, the | 97 // will be returned as converted. If it is not, the original escaped string will |
| 98 // original escaped string will be converted into a wide string and returned. | 98 // be converted into a wide string and returned. |
| 99 std::wstring UnescapeAndDecodeURLComponent(const std::string& text, | 99 // |
| 100 const char* codepage, | 100 // |offset_for_adjustment| may be NULL; if not, it is an offset into |text| that |
| 101 UnescapeRule::Type rules); | 101 // will be adjusted to point at the same logical place in the result string. If |
| 102 inline std::wstring UnescapeAndDecodeUTF8URLComponent( | 102 // this isn't possible because it points into the middle of an escape sequence |
| 103 const std::string& text, | 103 // or past the end of the string, it will be set to std::wstring::npos. |
| 104 UnescapeRule::Type rules) { | 104 std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text, |
| 105 return UnescapeAndDecodeURLComponent(text, "UTF-8", rules); | 105 UnescapeRule::Type rules, |
| 106 } | 106 size_t* offset_for_adjustment); |
| 107 | 107 |
| 108 // Deprecated ------------------------------------------------------------------ | 108 // Deprecated ------------------------------------------------------------------ |
| 109 | 109 |
| 110 // Escapes characters in text suitable for use as a query parameter value. | 110 // Escapes characters in text suitable for use as a query parameter value. |
| 111 // We %XX everything except alphanumerics and -_.!~*'() | 111 // We %XX everything except alphanumerics and -_.!~*'() |
| 112 // This is basically the same as encodeURIComponent in javascript. | 112 // This is basically the same as encodeURIComponent in javascript. |
| 113 // For the wstring version, we do a conversion to charset before encoding the | 113 // For the wstring version, we do a conversion to charset before encoding the |
| 114 // string. If the charset doesn't exist, we return false. | 114 // string. If the charset doesn't exist, we return false. |
| 115 // | 115 // |
| 116 // TODO(brettw) bug 1201094: This function should be removed. See the bug for | 116 // TODO(brettw) bug 1201094: This function should be removed. See the bug for |
| 117 // why and what callers should do instead. | 117 // why and what callers should do instead. |
| 118 std::string EscapeQueryParamValue(const std::string& text); | 118 std::string EscapeQueryParamValue(const std::string& text); |
| 119 bool EscapeQueryParamValue(const std::wstring& text, const char* codepage, | 119 bool EscapeQueryParamValue(const std::wstring& text, const char* codepage, |
| 120 std::wstring* escaped); | 120 std::wstring* escaped); |
| 121 | 121 |
| 122 // A specialized version of EscapeQueryParamValue for wide strings that | 122 // A specialized version of EscapeQueryParamValue for wide strings that |
| 123 // assumes the codepage is UTF8. This is provided as a convenience. | 123 // assumes the codepage is UTF8. This is provided as a convenience. |
| 124 // | 124 // |
| 125 // TODO(brettw) bug 1201094: This function should be removed. See the bug for | 125 // TODO(brettw) bug 1201094: This function should be removed. See the bug for |
| 126 // why and what callers should do instead. | 126 // why and what callers should do instead. |
| 127 std::wstring EscapeQueryParamValueUTF8(const std::wstring& text); | 127 std::wstring EscapeQueryParamValueUTF8(const std::wstring& text); |
| 128 | 128 |
| 129 #endif // #ifndef NET_BASE_ESCAPE_H__ | 129 #endif // #ifndef NET_BASE_ESCAPE_H__ |
| OLD | NEW |