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

Side by Side Diff: src/url_util.h

Issue 2939004: Add option to build googleurl as dll... (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 5 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
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #ifndef GOOGLEURL_SRC_URL_UTIL_H__ 30 #ifndef GOOGLEURL_SRC_URL_UTIL_H__
31 #define GOOGLEURL_SRC_URL_UTIL_H__ 31 #define GOOGLEURL_SRC_URL_UTIL_H__
32 32
33 #include <string> 33 #include <string>
34 34
35 #include "base/string16.h" 35 #include "base/string16.h"
36 #include "googleurl/src/url_common.h"
36 #include "googleurl/src/url_parse.h" 37 #include "googleurl/src/url_parse.h"
37 #include "googleurl/src/url_canon.h" 38 #include "googleurl/src/url_canon.h"
38 39
39 namespace url_util { 40 namespace url_util {
40 41
41 // Init ------------------------------------------------------------------------ 42 // Init ------------------------------------------------------------------------
42 43
43 // Initialization is NOT required, it will be implicitly initialized when first 44 // Initialization is NOT required, it will be implicitly initialized when first
44 // used. However, this implicit initialization is NOT threadsafe. If you are 45 // used. However, this implicit initialization is NOT threadsafe. If you are
45 // using this library in a threaded environment and don't have a consistent 46 // using this library in a threaded environment and don't have a consistent
46 // "first call" (an example might be calling "AddStandardScheme" with your 47 // "first call" (an example might be calling "AddStandardScheme" with your
47 // special application-specific schemes) then you will want to call initialize 48 // special application-specific schemes) then you will want to call initialize
48 // before spawning any threads. 49 // before spawning any threads.
49 // 50 //
50 // It is OK to call this function more than once, subsequent calls will simply 51 // It is OK to call this function more than once, subsequent calls will simply
51 // "noop", unless Shutdown() was called in the mean time. This will also be a 52 // "noop", unless Shutdown() was called in the mean time. This will also be a
52 // "noop" if other calls to the library have forced an initialization 53 // "noop" if other calls to the library have forced an initialization
53 // beforehand. 54 // beforehand.
54 void Initialize(); 55 GURL_API void Initialize();
55 56
56 // Cleanup is not required, except some strings may leak. For most user 57 // Cleanup is not required, except some strings may leak. For most user
57 // applications, this is fine. If you're using it in a library that may get 58 // applications, this is fine. If you're using it in a library that may get
58 // loaded and unloaded, you'll want to unload to properly clean up your 59 // loaded and unloaded, you'll want to unload to properly clean up your
59 // library. 60 // library.
60 void Shutdown(); 61 GURL_API void Shutdown();
61 62
62 // Schemes -------------------------------------------------------------------- 63 // Schemes --------------------------------------------------------------------
63 64
64 // Adds an application-defined scheme to the internal list of "standard" URL 65 // Adds an application-defined scheme to the internal list of "standard" URL
65 // schemes. This function is not threadsafe and can not be called concurrently 66 // schemes. This function is not threadsafe and can not be called concurrently
66 // with any other url_util function. It will assert if the list of standard 67 // with any other url_util function. It will assert if the list of standard
67 // schemes has been locked (see LockStandardSchemes). 68 // schemes has been locked (see LockStandardSchemes).
68 void AddStandardScheme(const char* new_scheme); 69 GURL_API void AddStandardScheme(const char* new_scheme);
69 70
70 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. 71 // Sets a flag to prevent future calls to AddStandardScheme from succeeding.
71 // 72 //
72 // This is designed to help prevent errors for multithreaded applications. 73 // This is designed to help prevent errors for multithreaded applications.
73 // Normal usage would be to call AddStandardScheme for your custom schemes at 74 // Normal usage would be to call AddStandardScheme for your custom schemes at
74 // the beginning of program initialization, and then LockStandardSchemes. This 75 // the beginning of program initialization, and then LockStandardSchemes. This
75 // prevents future callers from mistakenly calling AddStandardScheme when the 76 // prevents future callers from mistakenly calling AddStandardScheme when the
76 // program is running with multiple threads, where such usage would be 77 // program is running with multiple threads, where such usage would be
77 // dangerous. 78 // dangerous.
78 // 79 //
79 // We could have had AddStandardScheme use a lock instead, but that would add 80 // We could have had AddStandardScheme use a lock instead, but that would add
80 // some platform-specific dependencies we don't otherwise have now, and is 81 // some platform-specific dependencies we don't otherwise have now, and is
81 // overkill considering the normal usage is so simple. 82 // overkill considering the normal usage is so simple.
82 void LockStandardSchemes(); 83 GURL_API void LockStandardSchemes();
83 84
84 // Locates the scheme in the given string and places it into |found_scheme|, 85 // Locates the scheme in the given string and places it into |found_scheme|,
85 // which may be NULL to indicate the caller does not care about the range. 86 // which may be NULL to indicate the caller does not care about the range.
86 // 87 //
87 // Returns whether the given |compare| scheme matches the scheme found in the 88 // Returns whether the given |compare| scheme matches the scheme found in the
88 // input (if any). The |compare| scheme must be a valid canonical scheme or 89 // input (if any). The |compare| scheme must be a valid canonical scheme or
89 // the result of the comparison is undefined. 90 // the result of the comparison is undefined.
90 bool FindAndCompareScheme(const char* str, 91 GURL_API bool FindAndCompareScheme(const char* str,
91 int str_len, 92 int str_len,
92 const char* compare, 93 const char* compare,
93 url_parse::Component* found_scheme); 94 url_parse::Component* found_scheme);
94 bool FindAndCompareScheme(const char16* str, 95 GURL_API bool FindAndCompareScheme(const char16* str,
95 int str_len, 96 int str_len,
96 const char* compare, 97 const char* compare,
97 url_parse::Component* found_scheme); 98 url_parse::Component* found_scheme);
98 inline bool FindAndCompareScheme(const std::string& str, 99 inline bool FindAndCompareScheme(const std::string& str,
99 const char* compare, 100 const char* compare,
100 url_parse::Component* found_scheme) { 101 url_parse::Component* found_scheme) {
101 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), 102 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()),
102 compare, found_scheme); 103 compare, found_scheme);
103 } 104 }
104 inline bool FindAndCompareScheme(const string16& str, 105 inline bool FindAndCompareScheme(const string16& str,
105 const char* compare, 106 const char* compare,
106 url_parse::Component* found_scheme) { 107 url_parse::Component* found_scheme) {
107 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), 108 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()),
108 compare, found_scheme); 109 compare, found_scheme);
109 } 110 }
110 111
111 // Returns true if the given string represents a standard URL. This means that 112 // Returns true if the given string represents a standard URL. This means that
112 // either the scheme is in the list of known standard schemes. 113 // either the scheme is in the list of known standard schemes.
113 bool IsStandard(const char* spec, const url_parse::Component& scheme); 114 GURL_API bool IsStandard(const char* spec,
114 bool IsStandard(const char16* spec, const url_parse::Component& scheme); 115 const url_parse::Component& scheme);
116 GURL_API bool IsStandard(const char16* spec,
117 const url_parse::Component& scheme);
115 118
116 // TODO(brettw) remove this. This is a temporary compatibility hack to avoid 119 // TODO(brettw) remove this. This is a temporary compatibility hack to avoid
117 // breaking the WebKit build when this version is synced via Chrome. 120 // breaking the WebKit build when this version is synced via Chrome.
118 inline bool IsStandard(const char* spec, int spec_len, 121 inline bool IsStandard(const char* spec, int spec_len,
119 const url_parse::Component& scheme) { 122 const url_parse::Component& scheme) {
120 return IsStandard(spec, scheme); 123 return IsStandard(spec, scheme);
121 } 124 }
122 125
123 // URL library wrappers ------------------------------------------------------- 126 // URL library wrappers -------------------------------------------------------
124 127
125 // Parses the given spec according to the extracted scheme type. Normal users 128 // Parses the given spec according to the extracted scheme type. Normal users
126 // should use the URL object, although this may be useful if performance is 129 // should use the URL object, although this may be useful if performance is
127 // critical and you don't want to do the heap allocation for the std::string. 130 // critical and you don't want to do the heap allocation for the std::string.
128 // 131 //
129 // As with the url_canon::Canonicalize* functions, the charset converter can 132 // As with the url_canon::Canonicalize* functions, the charset converter can
130 // be NULL to use UTF-8 (it will be faster in this case). 133 // be NULL to use UTF-8 (it will be faster in this case).
131 // 134 //
132 // Returns true if a valid URL was produced, false if not. On failure, the 135 // Returns true if a valid URL was produced, false if not. On failure, the
133 // output and parsed structures will still be filled and will be consistent, 136 // output and parsed structures will still be filled and will be consistent,
134 // but they will not represent a loadable URL. 137 // but they will not represent a loadable URL.
135 bool Canonicalize(const char* spec, 138 GURL_API bool Canonicalize(const char* spec,
136 int spec_len, 139 int spec_len,
137 url_canon::CharsetConverter* charset_converter, 140 url_canon::CharsetConverter* charset_converter,
138 url_canon::CanonOutput* output, 141 url_canon::CanonOutput* output,
139 url_parse::Parsed* output_parsed); 142 url_parse::Parsed* output_parsed);
140 bool Canonicalize(const char16* spec, 143 GURL_API bool Canonicalize(const char16* spec,
141 int spec_len, 144 int spec_len,
142 url_canon::CharsetConverter* charset_converter, 145 url_canon::CharsetConverter* charset_converter,
143 url_canon::CanonOutput* output, 146 url_canon::CanonOutput* output,
144 url_parse::Parsed* output_parsed); 147 url_parse::Parsed* output_parsed);
145 148
146 // Resolves a potentially relative URL relative to the given parsed base URL. 149 // Resolves a potentially relative URL relative to the given parsed base URL.
147 // The base MUST be valid. The resulting canonical URL and parsed information 150 // The base MUST be valid. The resulting canonical URL and parsed information
148 // will be placed in to the given out variables. 151 // will be placed in to the given out variables.
149 // 152 //
150 // The relative need not be relative. If we discover that it's absolute, this 153 // The relative need not be relative. If we discover that it's absolute, this
151 // will produce a canonical version of that URL. See Canonicalize() for more 154 // will produce a canonical version of that URL. See Canonicalize() for more
152 // about the charset_converter. 155 // about the charset_converter.
153 // 156 //
154 // Returns true if the output is valid, false if the input could not produce 157 // Returns true if the output is valid, false if the input could not produce
155 // a valid URL. 158 // a valid URL.
156 bool ResolveRelative(const char* base_spec, 159 GURL_API bool ResolveRelative(const char* base_spec,
157 int base_spec_len, 160 int base_spec_len,
158 const url_parse::Parsed& base_parsed, 161 const url_parse::Parsed& base_parsed,
159 const char* relative, 162 const char* relative,
160 int relative_length, 163 int relative_length,
161 url_canon::CharsetConverter* charset_converter, 164 url_canon::CharsetConverter* charset_converter,
162 url_canon::CanonOutput* output, 165 url_canon::CanonOutput* output,
163 url_parse::Parsed* output_parsed); 166 url_parse::Parsed* output_parsed);
164 bool ResolveRelative(const char* base_spec, 167 GURL_API bool ResolveRelative(const char* base_spec,
165 int base_spec_len, 168 int base_spec_len,
166 const url_parse::Parsed& base_parsed, 169 const url_parse::Parsed& base_parsed,
167 const char16* relative, 170 const char16* relative,
168 int relative_length, 171 int relative_length,
169 url_canon::CharsetConverter* charset_converter, 172 url_canon::CharsetConverter* charset_converter,
170 url_canon::CanonOutput* output, 173 url_canon::CanonOutput* output,
171 url_parse::Parsed* output_parsed); 174 url_parse::Parsed* output_parsed);
172 175
173 // Replaces components in the given VALID input url. The new canonical URL info 176 // Replaces components in the given VALID input url. The new canonical URL info
174 // is written to output and out_parsed. 177 // is written to output and out_parsed.
175 // 178 //
176 // Returns true if the resulting URL is valid. 179 // Returns true if the resulting URL is valid.
177 bool ReplaceComponents(const char* spec, 180 GURL_API bool ReplaceComponents(
178 int spec_len, 181 const char* spec,
179 const url_parse::Parsed& parsed, 182 int spec_len,
180 const url_canon::Replacements<char>& replacements, 183 const url_parse::Parsed& parsed,
181 url_canon::CharsetConverter* charset_converter, 184 const url_canon::Replacements<char>& replacements,
182 url_canon::CanonOutput* output, 185 url_canon::CharsetConverter* charset_converter,
183 url_parse::Parsed* out_parsed); 186 url_canon::CanonOutput* output,
184 bool ReplaceComponents(const char* spec, 187 url_parse::Parsed* out_parsed);
185 int spec_len, 188 GURL_API bool ReplaceComponents(
186 const url_parse::Parsed& parsed, 189 const char* spec,
187 const url_canon::Replacements<char16>& replacements, 190 int spec_len,
188 url_canon::CharsetConverter* charset_converter, 191 const url_parse::Parsed& parsed,
189 url_canon::CanonOutput* output, 192 const url_canon::Replacements<char16>& replacements,
190 url_parse::Parsed* out_parsed); 193 url_canon::CharsetConverter* charset_converter,
194 url_canon::CanonOutput* output,
195 url_parse::Parsed* out_parsed);
191 196
192 // String helper functions ---------------------------------------------------- 197 // String helper functions ----------------------------------------------------
193 198
194 // Compare the lower-case form of the given string against the given ASCII 199 // Compare the lower-case form of the given string against the given ASCII
195 // string. This is useful for doing checking if an input string matches some 200 // string. This is useful for doing checking if an input string matches some
196 // token, and it is optimized to avoid intermediate string copies. 201 // token, and it is optimized to avoid intermediate string copies.
197 // 202 //
198 // The versions of this function that don't take a b_end assume that the b 203 // The versions of this function that don't take a b_end assume that the b
199 // string is NULL terminated. 204 // string is NULL terminated.
200 bool LowerCaseEqualsASCII(const char* a_begin, 205 GURL_API bool LowerCaseEqualsASCII(const char* a_begin,
201 const char* a_end, 206 const char* a_end,
202 const char* b); 207 const char* b);
203 bool LowerCaseEqualsASCII(const char* a_begin, 208 GURL_API bool LowerCaseEqualsASCII(const char* a_begin,
204 const char* a_end, 209 const char* a_end,
205 const char* b_begin, 210 const char* b_begin,
206 const char* b_end); 211 const char* b_end);
207 bool LowerCaseEqualsASCII(const char16* a_begin, 212 GURL_API bool LowerCaseEqualsASCII(const char16* a_begin,
208 const char16* a_end, 213 const char16* a_end,
209 const char* b); 214 const char* b);
215
216 // Unescapes the given string using URL escaping rules.
217 GURL_API void DecodeURLEscapeSequences(const char* input, int length,
218 url_canon::CanonOutputW* output);
210 219
211 } // namespace url_util 220 } // namespace url_util
212 221
213 #endif // GOOGLEURL_SRC_URL_UTIL_H__ 222 #endif // GOOGLEURL_SRC_URL_UTIL_H__
OLDNEW
« src/url_common.h ('K') | « src/url_parse.h ('k') | src/url_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698