| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 15 | 15 |
| 16 namespace net { |
| 17 |
| 18 // Escaping -------------------------------------------------------------------- |
| 19 |
| 20 // Escapes a file. This includes: |
| 21 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} |
| 22 NET_EXPORT std::string EscapePath(const std::string& path); |
| 23 |
| 24 // Escapes application/x-www-form-urlencoded content. This includes: |
| 25 // non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|} |
| 26 // Space is escaped as + (if use_plus is true) and other special characters |
| 27 // as %XX (hex). |
| 28 NET_EXPORT std::string EscapeUrlEncodedData(const std::string& path, |
| 29 bool use_plus); |
| 30 |
| 31 // Escapes all non-ASCII input. |
| 32 NET_EXPORT std::string EscapeNonASCII(const std::string& input); |
| 33 |
| 34 // Escapes characters in text suitable for use as an external protocol handler |
| 35 // command. |
| 36 // We %XX everything except alphanumerics and %-_.!~*'() and the restricted |
| 37 // chracters (;/?:@&=+$,). |
| 38 NET_EXPORT std::string EscapeExternalHandlerValue(const std::string& text); |
| 39 |
| 40 // Appends the given character to the output string, escaping the character if |
| 41 // the character would be interpretted as an HTML delimiter. |
| 42 NET_EXPORT void AppendEscapedCharForHTML(char c, std::string* output); |
| 43 |
| 44 // Escapes chars that might cause this text to be interpretted as HTML tags. |
| 45 NET_EXPORT std::string EscapeForHTML(const std::string& text); |
| 46 NET_EXPORT string16 EscapeForHTML(const string16& text); |
| 47 |
| 16 // Unescaping ------------------------------------------------------------------ | 48 // Unescaping ------------------------------------------------------------------ |
| 17 | 49 |
| 18 class UnescapeRule { | 50 class UnescapeRule { |
| 19 public: | 51 public: |
| 20 // A combination of the following flags that is passed to the unescaping | 52 // A combination of the following flags that is passed to the unescaping |
| 21 // functions. | 53 // functions. |
| 22 typedef uint32 Type; | 54 typedef uint32 Type; |
| 23 | 55 |
| 24 enum { | 56 enum { |
| 25 // Don't unescape anything at all. | 57 // Don't unescape anything at all. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 // Unescapes control characters such as %01. This INCLUDES NULLs. This is | 80 // Unescapes control characters such as %01. This INCLUDES NULLs. This is |
| 49 // used for rare cases such as data: URL decoding where the result is binary | 81 // used for rare cases such as data: URL decoding where the result is binary |
| 50 // data. You should not use this for normal URLs! | 82 // data. You should not use this for normal URLs! |
| 51 CONTROL_CHARS = 8, | 83 CONTROL_CHARS = 8, |
| 52 | 84 |
| 53 // URL queries use "+" for space. This flag controls that replacement. | 85 // URL queries use "+" for space. This flag controls that replacement. |
| 54 REPLACE_PLUS_WITH_SPACE = 16, | 86 REPLACE_PLUS_WITH_SPACE = 16, |
| 55 }; | 87 }; |
| 56 }; | 88 }; |
| 57 | 89 |
| 58 namespace net { | |
| 59 | |
| 60 // Escaping -------------------------------------------------------------------- | |
| 61 | |
| 62 // escape a file. this includes: | |
| 63 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} | |
| 64 NET_EXPORT std::string EscapePath(const std::string& path); | |
| 65 | |
| 66 // Escape application/x-www-form-urlencoded content. This includes: | |
| 67 // non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|} | |
| 68 // Space is escaped as + (if use_plus is true) and other special characters | |
| 69 // as %XX (hex). | |
| 70 NET_EXPORT std::string EscapeUrlEncodedData(const std::string& path, | |
| 71 bool use_plus); | |
| 72 | |
| 73 // Escape all non-ASCII input. | |
| 74 NET_EXPORT std::string EscapeNonASCII(const std::string& input); | |
| 75 | |
| 76 // Escapes characters in text suitable for use as an external protocol handler | |
| 77 // command. | |
| 78 // We %XX everything except alphanumerics and %-_.!~*'() and the restricted | |
| 79 // chracters (;/?:@&=+$,). | |
| 80 NET_EXPORT std::string EscapeExternalHandlerValue(const std::string& text); | |
| 81 | |
| 82 // Append the given character to the output string, escaping the character if | |
| 83 // the character would be interpretted as an HTML delimiter. | |
| 84 NET_EXPORT void AppendEscapedCharForHTML(char c, std::string* output); | |
| 85 | |
| 86 // Escape chars that might cause this text to be interpretted as HTML tags. | |
| 87 NET_EXPORT std::string EscapeForHTML(const std::string& text); | |
| 88 NET_EXPORT string16 EscapeForHTML(const string16& text); | |
| 89 | |
| 90 // Unescapes |escaped_text| and returns the result. | 90 // Unescapes |escaped_text| and returns the result. |
| 91 // Unescaping consists of looking for the exact pattern "%XX", where each X is | 91 // Unescaping consists of looking for the exact pattern "%XX", where each X is |
| 92 // a hex digit, and converting to the character with the numerical value of | 92 // a hex digit, and converting to the character with the numerical value of |
| 93 // those digits. Thus "i%20=%203%3b" unescapes to "i = 3;". | 93 // those digits. Thus "i%20=%203%3b" unescapes to "i = 3;". |
| 94 // | 94 // |
| 95 // Watch out: this doesn't necessarily result in the correct final result, | 95 // Watch out: this doesn't necessarily result in the correct final result, |
| 96 // because the encoding may be unknown. For example, the input might be ASCII, | 96 // because the encoding may be unknown. For example, the input might be ASCII, |
| 97 // which, after unescaping, is supposed to be interpreted as UTF-8, and then | 97 // which, after unescaping, is supposed to be interpreted as UTF-8, and then |
| 98 // converted into full UTF-16 chars. This function won't tell you if any | 98 // converted into full UTF-16 chars. This function won't tell you if any |
| 99 // conversions need to take place, it only unescapes. | 99 // conversions need to take place, it only unescapes. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 // offset will be set to string16::npos. |offset[s]_for_adjustment| may be NULL. | 113 // offset will be set to string16::npos. |offset[s]_for_adjustment| may be NULL. |
| 114 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponent( | 114 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponent( |
| 115 const std::string& text, | 115 const std::string& text, |
| 116 UnescapeRule::Type rules, | 116 UnescapeRule::Type rules, |
| 117 size_t* offset_for_adjustment); | 117 size_t* offset_for_adjustment); |
| 118 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponentWithOffsets( | 118 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponentWithOffsets( |
| 119 const std::string& text, | 119 const std::string& text, |
| 120 UnescapeRule::Type rules, | 120 UnescapeRule::Type rules, |
| 121 std::vector<size_t>* offsets_for_adjustment); | 121 std::vector<size_t>* offsets_for_adjustment); |
| 122 | 122 |
| 123 // Unescape the following ampersand character codes from |text|: | 123 // Unescapes the following ampersand character codes from |text|: |
| 124 // < > & " ' | 124 // < > & " ' |
| 125 NET_EXPORT string16 UnescapeForHTML(const string16& text); | 125 NET_EXPORT string16 UnescapeForHTML(const string16& text); |
| 126 | 126 |
| 127 // Deprecated ------------------------------------------------------------------ | 127 // Deprecated ------------------------------------------------------------------ |
| 128 | 128 |
| 129 // Escapes characters in text suitable for use as a query parameter value. | 129 // Escapes characters in text suitable for use as a query parameter value. |
| 130 // We %XX everything except alphanumerics and -_.!~*'() | 130 // We %XX everything except alphanumerics and -_.!~*'() |
| 131 // Spaces change to "+" unless you pass usePlus=false. | 131 // Spaces change to "+" unless you pass usePlus=false. |
| 132 // This is basically the same as encodeURIComponent in javascript. | 132 // This is basically the same as encodeURIComponent in javascript. |
| 133 // For the string16 version, we do a conversion to charset before encoding the | 133 // For the string16 version, we do a conversion to charset before encoding the |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 void operator()(size_t& offset); | 157 void operator()(size_t& offset); |
| 158 | 158 |
| 159 const Adjustments& adjustments; | 159 const Adjustments& adjustments; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 } // namespace internal | 162 } // namespace internal |
| 163 | 163 |
| 164 } // namespace net | 164 } // namespace net |
| 165 | 165 |
| 166 #endif // NET_BASE_ESCAPE_H_ | 166 #endif // NET_BASE_ESCAPE_H_ |
| OLD | NEW |