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

Side by Side Diff: url_util.h

Issue 2029803003: Update to Chromium //url at Chromium commit 79dc59ac7602413181079ecb463873e29a1d7d0a. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/domokit/gurl@master
Patch Set: Created 4 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
« no previous file with comments | « url_test_utils.h ('k') | url_util.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 URL_URL_UTIL_H_ 5 #ifndef URL_URL_UTIL_H_
6 #define URL_URL_UTIL_H_ 6 #define URL_URL_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "url/third_party/mozilla/url_parse.h"
11 #include "url/url_canon.h" 12 #include "url/url_canon.h"
12 #include "url/url_constants.h" 13 #include "url/url_constants.h"
13 #include "url/url_export.h" 14 #include "url/url_export.h"
14 #include "url/url_parse.h"
15 15
16 namespace url { 16 namespace url {
17 17
18 // Init ------------------------------------------------------------------------ 18 // Init ------------------------------------------------------------------------
19 19
20 // Initialization is NOT required, it will be implicitly initialized when first 20 // Initialization is NOT required, it will be implicitly initialized when first
21 // used. However, this implicit initialization is NOT threadsafe. If you are 21 // used. However, this implicit initialization is NOT threadsafe. If you are
22 // using this library in a threaded environment and don't have a consistent 22 // using this library in a threaded environment and don't have a consistent
23 // "first call" (an example might be calling "AddStandardScheme" with your 23 // "first call" (an example might be calling AddStandardScheme with your special
24 // special application-specific schemes) then you will want to call initialize 24 // application-specific schemes) then you will want to call initialize before
25 // before spawning any threads. 25 // spawning any threads.
26 // 26 //
27 // It is OK to call this function more than once, subsequent calls will simply 27 // It is OK to call this function more than once, subsequent calls will be
28 // "noop", unless Shutdown() was called in the mean time. This will also be a 28 // no-ops, unless Shutdown was called in the mean time. This will also be a
29 // "noop" if other calls to the library have forced an initialization 29 // no-op if other calls to the library have forced an initialization beforehand.
30 // beforehand.
31 URL_EXPORT void Initialize(); 30 URL_EXPORT void Initialize();
32 31
33 // Cleanup is not required, except some strings may leak. For most user 32 // Cleanup is not required, except some strings may leak. For most user
34 // applications, this is fine. If you're using it in a library that may get 33 // applications, this is fine. If you're using it in a library that may get
35 // loaded and unloaded, you'll want to unload to properly clean up your 34 // loaded and unloaded, you'll want to unload to properly clean up your
36 // library. 35 // library.
37 URL_EXPORT void Shutdown(); 36 URL_EXPORT void Shutdown();
38 37
39 // Schemes -------------------------------------------------------------------- 38 // Schemes --------------------------------------------------------------------
40 39
41 // Adds an application-defined scheme to the internal list of "standard" URL 40 // Adds an application-defined scheme to the internal list of "standard-format"
42 // schemes. This function is not threadsafe and can not be called concurrently 41 // URL schemes. A standard-format scheme adheres to what RFC 3986 calls "generic
43 // with any other url_util function. It will assert if the list of standard 42 // URI syntax" (https://tools.ietf.org/html/rfc3986#section-3).
44 // schemes has been locked (see LockStandardSchemes). 43 //
44 // This function is not threadsafe and can not be called concurrently with any
45 // other url_util function. It will assert if the list of standard schemes has
46 // been locked (see LockStandardSchemes).
45 URL_EXPORT void AddStandardScheme(const char* new_scheme); 47 URL_EXPORT void AddStandardScheme(const char* new_scheme);
46 48
47 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. 49 // Sets a flag to prevent future calls to AddStandardScheme from succeeding.
48 // 50 //
49 // This is designed to help prevent errors for multithreaded applications. 51 // This is designed to help prevent errors for multithreaded applications.
50 // Normal usage would be to call AddStandardScheme for your custom schemes at 52 // Normal usage would be to call AddStandardScheme for your custom schemes at
51 // the beginning of program initialization, and then LockStandardSchemes. This 53 // the beginning of program initialization, and then LockStandardSchemes. This
52 // prevents future callers from mistakenly calling AddStandardScheme when the 54 // prevents future callers from mistakenly calling AddStandardScheme when the
53 // program is running with multiple threads, where such usage would be 55 // program is running with multiple threads, where such usage would be
54 // dangerous. 56 // dangerous.
(...skipping 23 matching lines...) Expand all
78 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), 80 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()),
79 compare, found_scheme); 81 compare, found_scheme);
80 } 82 }
81 inline bool FindAndCompareScheme(const base::string16& str, 83 inline bool FindAndCompareScheme(const base::string16& str,
82 const char* compare, 84 const char* compare,
83 Component* found_scheme) { 85 Component* found_scheme) {
84 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), 86 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()),
85 compare, found_scheme); 87 compare, found_scheme);
86 } 88 }
87 89
88 // Returns true if the given string represents a standard URL. This means that 90 // Returns true if the given string represents a URL whose scheme is in the list
89 // either the scheme is in the list of known standard schemes. 91 // of known standard-format schemes (see AddStandardScheme).
90 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); 92 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme);
91 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); 93 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme);
92 94
93 // TODO(brettw) remove this. This is a temporary compatibility hack to avoid
94 // breaking the WebKit build when this version is synced via Chrome.
95 inline bool IsStandard(const char* spec,
96 int spec_len,
97 const Component& scheme) {
98 return IsStandard(spec, scheme);
99 }
100
101 // URL library wrappers ------------------------------------------------------- 95 // URL library wrappers -------------------------------------------------------
102 96
103 // Parses the given spec according to the extracted scheme type. Normal users 97 // Parses the given spec according to the extracted scheme type. Normal users
104 // should use the URL object, although this may be useful if performance is 98 // should use the URL object, although this may be useful if performance is
105 // critical and you don't want to do the heap allocation for the std::string. 99 // critical and you don't want to do the heap allocation for the std::string.
106 // 100 //
107 // As with the Canonicalize* functions, the charset converter can 101 // As with the Canonicalize* functions, the charset converter can
108 // be NULL to use UTF-8 (it will be faster in this case). 102 // be NULL to use UTF-8 (it will be faster in this case).
109 // 103 //
110 // Returns true if a valid URL was produced, false if not. On failure, the 104 // Returns true if a valid URL was produced, false if not. On failure, the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Parsed* output_parsed); 137 Parsed* output_parsed);
144 URL_EXPORT bool ResolveRelative(const char* base_spec, 138 URL_EXPORT bool ResolveRelative(const char* base_spec,
145 int base_spec_len, 139 int base_spec_len,
146 const Parsed& base_parsed, 140 const Parsed& base_parsed,
147 const base::char16* relative, 141 const base::char16* relative,
148 int relative_length, 142 int relative_length,
149 CharsetConverter* charset_converter, 143 CharsetConverter* charset_converter,
150 CanonOutput* output, 144 CanonOutput* output,
151 Parsed* output_parsed); 145 Parsed* output_parsed);
152 146
153 // Replaces components in the given VALID input url. The new canonical URL info 147 // Replaces components in the given VALID input URL. The new canonical URL info
154 // is written to output and out_parsed. 148 // is written to output and out_parsed.
155 // 149 //
156 // Returns true if the resulting URL is valid. 150 // Returns true if the resulting URL is valid.
157 URL_EXPORT bool ReplaceComponents(const char* spec, 151 URL_EXPORT bool ReplaceComponents(const char* spec,
158 int spec_len, 152 int spec_len,
159 const Parsed& parsed, 153 const Parsed& parsed,
160 const Replacements<char>& replacements, 154 const Replacements<char>& replacements,
161 CharsetConverter* charset_converter, 155 CharsetConverter* charset_converter,
162 CanonOutput* output, 156 CanonOutput* output,
163 Parsed* out_parsed); 157 Parsed* out_parsed);
164 URL_EXPORT bool ReplaceComponents( 158 URL_EXPORT bool ReplaceComponents(
165 const char* spec, 159 const char* spec,
166 int spec_len, 160 int spec_len,
167 const Parsed& parsed, 161 const Parsed& parsed,
168 const Replacements<base::char16>& replacements, 162 const Replacements<base::char16>& replacements,
169 CharsetConverter* charset_converter, 163 CharsetConverter* charset_converter,
170 CanonOutput* output, 164 CanonOutput* output,
171 Parsed* out_parsed); 165 Parsed* out_parsed);
172 166
173 // String helper functions ---------------------------------------------------- 167 // String helper functions ----------------------------------------------------
174 168
175 // Compare the lower-case form of the given string against the given ASCII
176 // string. This is useful for doing checking if an input string matches some
177 // token, and it is optimized to avoid intermediate string copies.
178 //
179 // The versions of this function that don't take a b_end assume that the b
180 // string is NULL terminated.
181 URL_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
182 const char* a_end,
183 const char* b);
184 URL_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
185 const char* a_end,
186 const char* b_begin,
187 const char* b_end);
188 URL_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin,
189 const base::char16* a_end,
190 const char* b);
191
192 // Unescapes the given string using URL escaping rules. 169 // Unescapes the given string using URL escaping rules.
193 URL_EXPORT void DecodeURLEscapeSequences(const char* input, 170 URL_EXPORT void DecodeURLEscapeSequences(const char* input,
194 int length, 171 int length,
195 CanonOutputW* output); 172 CanonOutputW* output);
196 173
197 // Escapes the given string as defined by the JS method encodeURIComponent. See 174 // Escapes the given string as defined by the JS method encodeURIComponent. See
198 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR IComponent 175 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR IComponent
199 URL_EXPORT void EncodeURIComponent(const char* input, 176 URL_EXPORT void EncodeURIComponent(const char* input,
200 int length, 177 int length,
201 CanonOutput* output); 178 CanonOutput* output);
202 179
203 } // namespace url 180 } // namespace url
204 181
205 #endif // URL_URL_UTIL_H_ 182 #endif // URL_URL_UTIL_H_
OLDNEW
« no previous file with comments | « url_test_utils.h ('k') | url_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698