| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Unescapes |escaped_text| and returns the result. | 85 // Unescapes |escaped_text| and returns the result. |
| 86 // Unescaping consists of looking for the exact pattern "%XX", where each X is | 86 // Unescaping consists of looking for the exact pattern "%XX", where each X is |
| 87 // a hex digit, and converting to the character with the numerical value of | 87 // a hex digit, and converting to the character with the numerical value of |
| 88 // those digits. Thus "i%20=%203%3b" unescapes to "i = 3;". | 88 // those digits. Thus "i%20=%203%3b" unescapes to "i = 3;". |
| 89 // | 89 // |
| 90 // Watch out: this doesn't necessarily result in the correct final result, | 90 // Watch out: this doesn't necessarily result in the correct final result, |
| 91 // because the encoding may be unknown. For example, the input might be ASCII, | 91 // because the encoding may be unknown. For example, the input might be ASCII, |
| 92 // which, after unescaping, is supposed to be interpreted as UTF-8, and then | 92 // which, after unescaping, is supposed to be interpreted as UTF-8, and then |
| 93 // converted into full wide chars. This function won't tell you if any | 93 // converted into full UTF-16 chars. This function won't tell you if any |
| 94 // conversions need to take place, it only unescapes. | 94 // conversions need to take place, it only unescapes. |
| 95 std::string UnescapeURLComponent(const std::string& escaped_text, | 95 std::string UnescapeURLComponent(const std::string& escaped_text, |
| 96 UnescapeRule::Type rules); | 96 UnescapeRule::Type rules); |
| 97 string16 UnescapeURLComponent(const string16& escaped_text, | 97 string16 UnescapeURLComponent(const string16& escaped_text, |
| 98 UnescapeRule::Type rules); | 98 UnescapeRule::Type rules); |
| 99 | 99 |
| 100 // Unescapes the given substring as a URL, and then tries to interpret the | 100 // Unescapes the given substring as a URL, and then tries to interpret the |
| 101 // result as being encoded as UTF-8. If the result is convertable into UTF-8, it | 101 // result as being encoded as UTF-8. If the result is convertable into UTF-8, it |
| 102 // will be returned as converted. If it is not, the original escaped string will | 102 // will be returned as converted. If it is not, the original escaped string will |
| 103 // be converted into a string16 and returned. (|offset[s]_for_adjustment|) | 103 // be converted into a string16 and returned. (|offset[s]_for_adjustment|) |
| 104 // specifies one or more offsets into the source strings; each offset will be | 104 // specifies one or more offsets into the source strings; each offset will be |
| 105 // adjusted to point at the same logical place in the result strings during | 105 // adjusted to point at the same logical place in the result strings during |
| 106 // decoding. If this isn't possible because an offset points past the end of | 106 // decoding. If this isn't possible because an offset points past the end of |
| 107 // the source strings or into the middle of a multibyte sequence, the offending | 107 // the source strings or into the middle of a multibyte sequence, the offending |
| 108 // offset will be set to std::wstring::npos. |offset[s]_for_adjustment| may be | 108 // offset will be set to string16::npos. |offset[s]_for_adjustment| may be NULL. |
| 109 // NULL. | |
| 110 string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text, | 109 string16 UnescapeAndDecodeUTF8URLComponent(const std::string& text, |
| 111 UnescapeRule::Type rules, | 110 UnescapeRule::Type rules, |
| 112 size_t* offset_for_adjustment); | 111 size_t* offset_for_adjustment); |
| 113 string16 UnescapeAndDecodeUTF8URLComponentWithOffsets( | 112 string16 UnescapeAndDecodeUTF8URLComponentWithOffsets( |
| 114 const std::string& text, | 113 const std::string& text, |
| 115 UnescapeRule::Type rules, | 114 UnescapeRule::Type rules, |
| 116 std::vector<size_t>* offsets_for_adjustment); | 115 std::vector<size_t>* offsets_for_adjustment); |
| 117 | 116 |
| 118 // Unescape the following ampersand character codes from |text|: | 117 // Unescape the following ampersand character codes from |text|: |
| 119 // < > & " ' | 118 // < > & " ' |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 struct AdjustEncodingOffset { | 141 struct AdjustEncodingOffset { |
| 143 typedef std::vector<size_t> Adjustments; | 142 typedef std::vector<size_t> Adjustments; |
| 144 | 143 |
| 145 explicit AdjustEncodingOffset(const Adjustments& adjustments); | 144 explicit AdjustEncodingOffset(const Adjustments& adjustments); |
| 146 void operator()(size_t& offset); | 145 void operator()(size_t& offset); |
| 147 | 146 |
| 148 const Adjustments& adjustments; | 147 const Adjustments& adjustments; |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 #endif // NET_BASE_ESCAPE_H_ | 150 #endif // NET_BASE_ESCAPE_H_ |
| OLD | NEW |