Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: net/base/escape.h

Issue 10444117: Escape search terms correctly in the path portion of a custom search engine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/accessibility/browser_accessibility_win.cc ('k') | net/base/escape.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 { 16 namespace net {
17 17
18 // Escaping -------------------------------------------------------------------- 18 // Escaping --------------------------------------------------------------------
19 19
20 // Escapes a file. This includes: 20 // Escapes characters in text suitable for use as a query parameter value.
21 // We %XX everything except alphanumerics and -_.!~*'()
22 // Spaces change to "+" unless you pass usePlus=false.
23 // This is basically the same as encodeURIComponent in javascript.
24 NET_EXPORT std::string EscapeQueryParamValue(const std::string& text,
25 bool use_plus);
26
27 // Escapes a partial or complete file/pathname. This includes:
21 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} 28 // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|}
29 // For the string16 version, we attempt a conversion to |codepage| before
30 // encoding the string. If this conversion fails, we return false.
22 NET_EXPORT std::string EscapePath(const std::string& path); 31 NET_EXPORT std::string EscapePath(const std::string& path);
23 32
24 // Escapes application/x-www-form-urlencoded content. This includes: 33 // Escapes application/x-www-form-urlencoded content. This includes:
25 // non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|} 34 // non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|}
26 // Space is escaped as + (if use_plus is true) and other special characters 35 // Space is escaped as + (if use_plus is true) and other special characters
27 // as %XX (hex). 36 // as %XX (hex).
28 NET_EXPORT std::string EscapeUrlEncodedData(const std::string& path, 37 NET_EXPORT std::string EscapeUrlEncodedData(const std::string& path,
29 bool use_plus); 38 bool use_plus);
30 39
31 // Escapes all non-ASCII input. 40 // Escapes all non-ASCII input.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 size_t* offset_for_adjustment); 126 size_t* offset_for_adjustment);
118 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponentWithOffsets( 127 NET_EXPORT string16 UnescapeAndDecodeUTF8URLComponentWithOffsets(
119 const std::string& text, 128 const std::string& text,
120 UnescapeRule::Type rules, 129 UnescapeRule::Type rules,
121 std::vector<size_t>* offsets_for_adjustment); 130 std::vector<size_t>* offsets_for_adjustment);
122 131
123 // Unescapes the following ampersand character codes from |text|: 132 // Unescapes the following ampersand character codes from |text|:
124 // &lt; &gt; &amp; &quot; &#39; 133 // &lt; &gt; &amp; &quot; &#39;
125 NET_EXPORT string16 UnescapeForHTML(const string16& text); 134 NET_EXPORT string16 UnescapeForHTML(const string16& text);
126 135
127 // Deprecated ------------------------------------------------------------------
128
129 // Escapes characters in text suitable for use as a query parameter value.
130 // We %XX everything except alphanumerics and -_.!~*'()
131 // Spaces change to "+" unless you pass usePlus=false.
132 // This is basically the same as encodeURIComponent in javascript.
133 // For the string16 version, we do a conversion to charset before encoding the
134 // string. If the charset doesn't exist, we return false.
135 NET_EXPORT std::string EscapeQueryParamValue(const std::string& text,
136 bool use_plus);
137 NET_EXPORT bool EscapeQueryParamValue(const string16& text,
138 const char* codepage,
139 bool use_plus,
140 string16* escaped);
141
142 // A specialized version of EscapeQueryParamValue for string16s that
143 // assumes the codepage is UTF8. This is provided as a convenience.
144 NET_EXPORT string16 EscapeQueryParamValueUTF8(const string16& text,
145 bool use_plus);
146
147 namespace internal { 136 namespace internal {
148 137
149 // Private Functions (Exposed for Unit Testing) -------------------------------- 138 // Private Functions (Exposed for Unit Testing) --------------------------------
150 139
151 // A function called by std::for_each that will adjust any offset which occurs 140 // A function called by std::for_each that will adjust any offset which occurs
152 // after one or more encoded characters. 141 // after one or more encoded characters.
153 struct NET_EXPORT_PRIVATE AdjustEncodingOffset { 142 struct NET_EXPORT_PRIVATE AdjustEncodingOffset {
154 typedef std::vector<size_t> Adjustments; 143 typedef std::vector<size_t> Adjustments;
155 144
156 explicit AdjustEncodingOffset(const Adjustments& adjustments); 145 explicit AdjustEncodingOffset(const Adjustments& adjustments);
157 void operator()(size_t& offset); 146 void operator()(size_t& offset);
158 147
159 const Adjustments& adjustments; 148 const Adjustments& adjustments;
160 }; 149 };
161 150
162 } // namespace internal 151 } // namespace internal
163 152
164 } // namespace net 153 } // namespace net
165 154
166 #endif // NET_BASE_ESCAPE_H_ 155 #endif // NET_BASE_ESCAPE_H_
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility_win.cc ('k') | net/base/escape.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698