OLD | NEW |
1 /* Based on nsURLParsers.cc from Mozilla | 1 /* Based on nsURLParsers.cc from Mozilla |
2 * ------------------------------------- | 2 * ------------------------------------- |
3 * The contents of this file are subject to the Mozilla Public License Version | 3 * The contents of this file are subject to the Mozilla Public License Version |
4 * 1.1 (the "License"); you may not use this file except in compliance with | 4 * 1.1 (the "License"); you may not use this file except in compliance with |
5 * the License. You may obtain a copy of the License at | 5 * the License. You may obtain a copy of the License at |
6 * http://www.mozilla.org/MPL/ | 6 * http://www.mozilla.org/MPL/ |
7 * | 7 * |
8 * Software distributed under the License is distributed on an "AS IS" basis, | 8 * Software distributed under the License is distributed on an "AS IS" basis, |
9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
10 * for the specific language governing rights and limitations under the | 10 * for the specific language governing rights and limitations under the |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 full_path = Component(); | 305 full_path = Component(); |
306 else // Everything starting from the slash to the end is the path. | 306 else // Everything starting from the slash to the end is the path. |
307 full_path = Component(end_auth, spec_len - end_auth); | 307 full_path = Component(end_auth, spec_len - end_auth); |
308 | 308 |
309 // Now parse those two sub-parts. | 309 // Now parse those two sub-parts. |
310 DoParseAuthority(spec, authority, &parsed->username, &parsed->password, | 310 DoParseAuthority(spec, authority, &parsed->username, &parsed->password, |
311 &parsed->host, &parsed->port); | 311 &parsed->host, &parsed->port); |
312 ParsePath(spec, full_path, &parsed->path, &parsed->query, &parsed->ref); | 312 ParsePath(spec, full_path, &parsed->path, &parsed->query, &parsed->ref); |
313 } | 313 } |
314 | 314 |
| 315 // The main parsing function for standard URLs. Standard URLs have a scheme, |
| 316 // host, path, etc. |
| 317 template<typename CHAR> |
| 318 void DoParseStandardURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
| 319 DCHECK(spec_len >= 0); |
| 320 |
| 321 // Strip leading & trailing spaces and control characters. |
| 322 int begin = 0; |
| 323 TrimURL(spec, &begin, &spec_len); |
| 324 |
| 325 int after_scheme; |
| 326 if (DoExtractScheme(spec, spec_len, &parsed->scheme)) { |
| 327 after_scheme = parsed->scheme.end() + 1; // Skip past the colon. |
| 328 } else { |
| 329 // Say there's no scheme when there is no colon. We could also say that |
| 330 // everything is the scheme. Both would produce an invalid URL, but this way |
| 331 // seems less wrong in more cases. |
| 332 parsed->scheme.reset(); |
| 333 after_scheme = begin; |
| 334 } |
| 335 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
| 336 } |
| 337 |
315 template<typename CHAR> | 338 template<typename CHAR> |
316 void DoParseFileSystemURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 339 void DoParseFileSystemURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
317 DCHECK(spec_len >= 0); | 340 DCHECK(spec_len >= 0); |
318 | 341 |
319 // Get the unused parts of the URL out of the way. | 342 // Get the unused parts of the URL out of the way. |
320 parsed->username.reset(); | 343 parsed->username.reset(); |
321 parsed->password.reset(); | 344 parsed->password.reset(); |
322 parsed->host.reset(); | 345 parsed->host.reset(); |
323 parsed->port.reset(); | 346 parsed->port.reset(); |
324 parsed->path.reset(); // May use this; reset for convenience. | 347 parsed->path.reset(); // May use this; reset for convenience. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 int inner_path_end = inner_parsed.path.begin + 1; // skip the leading slash | 444 int inner_path_end = inner_parsed.path.begin + 1; // skip the leading slash |
422 while (inner_path_end < spec_len && | 445 while (inner_path_end < spec_len && |
423 !IsURLSlash(spec[inner_path_end])) | 446 !IsURLSlash(spec[inner_path_end])) |
424 ++inner_path_end; | 447 ++inner_path_end; |
425 parsed->path.begin = inner_path_end; | 448 parsed->path.begin = inner_path_end; |
426 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; | 449 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; |
427 parsed->path.len = inner_parsed.path.len - new_inner_path_length; | 450 parsed->path.len = inner_parsed.path.len - new_inner_path_length; |
428 parsed->inner_parsed()->path.len = new_inner_path_length; | 451 parsed->inner_parsed()->path.len = new_inner_path_length; |
429 } | 452 } |
430 | 453 |
431 // The main parsing function for standard URLs. Standard URLs have a scheme, | |
432 // host, path, etc. | |
433 template<typename CHAR> | |
434 void DoParseStandardURL(const CHAR* spec, int spec_len, Parsed* parsed) { | |
435 DCHECK(spec_len >= 0); | |
436 | |
437 // Strip leading & trailing spaces and control characters. | |
438 int begin = 0; | |
439 TrimURL(spec, &begin, &spec_len); | |
440 | |
441 int after_scheme; | |
442 if (DoExtractScheme(spec, spec_len, &parsed->scheme)) { | |
443 after_scheme = parsed->scheme.end() + 1; // Skip past the colon. | |
444 } else { | |
445 // Say there's no scheme when there is no colon. We could also say that | |
446 // everything is the scheme. Both would produce an invalid URL, but this way | |
447 // seems less wrong in more cases. | |
448 parsed->scheme.reset(); | |
449 after_scheme = begin; | |
450 } | |
451 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | |
452 } | |
453 | |
454 // Initializes a path URL which is merely a scheme followed by a path. Examples | 454 // Initializes a path URL which is merely a scheme followed by a path. Examples |
455 // include "about:foo" and "javascript:alert('bar');" | 455 // include "about:foo" and "javascript:alert('bar');" |
456 template<typename CHAR> | 456 template<typename CHAR> |
457 void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 457 void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
458 // Get the non-path and non-scheme parts of the URL out of the way, we never | 458 // Get the non-path and non-scheme parts of the URL out of the way, we never |
459 // use them. | 459 // use them. |
460 parsed->username.reset(); | 460 parsed->username.reset(); |
461 parsed->password.reset(); | 461 parsed->password.reset(); |
462 parsed->host.reset(); | 462 parsed->host.reset(); |
463 parsed->port.reset(); | 463 parsed->port.reset(); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 } | 913 } |
914 | 914 |
915 void ParseAfterScheme(const char16* spec, | 915 void ParseAfterScheme(const char16* spec, |
916 int spec_len, | 916 int spec_len, |
917 int after_scheme, | 917 int after_scheme, |
918 Parsed* parsed) { | 918 Parsed* parsed) { |
919 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 919 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
920 } | 920 } |
921 | 921 |
922 } // namespace url_parse | 922 } // namespace url_parse |
OLD | NEW |