| 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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 557 |
| 558 // For compatability with the standard URL parser, treat no path as | 558 // For compatability with the standard URL parser, treat no path as |
| 559 // -1, rather than having a length of 0 | 559 // -1, rather than having a length of 0 |
| 560 if (path_begin == path_end) { | 560 if (path_begin == path_end) { |
| 561 parsed->path.reset(); | 561 parsed->path.reset(); |
| 562 } else { | 562 } else { |
| 563 parsed->path = MakeRange(path_begin, path_end); | 563 parsed->path = MakeRange(path_begin, path_end); |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 template <typename CHAR> |
| 568 void DoParseNonStandardURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
| 569 // Get the non-scheme parts of the URL out of the way, we don't know how to |
| 570 // interpret them. |
| 571 parsed->username.reset(); |
| 572 parsed->password.reset(); |
| 573 parsed->host.reset(); |
| 574 parsed->port.reset(); |
| 575 parsed->path.reset(); |
| 576 parsed->query.reset(); |
| 577 parsed->ref.reset(); |
| 578 |
| 579 // Strip leading & trailing spaces and control characters. |
| 580 int scheme_begin = 0; |
| 581 TrimURL(spec, &scheme_begin, &spec_len); |
| 582 |
| 583 // Handle empty specs or ones that contain only whitespace or control chars. |
| 584 if (scheme_begin == spec_len) { |
| 585 parsed->scheme.reset(); |
| 586 parsed->path.reset(); |
| 587 return; |
| 588 } |
| 589 |
| 590 // Extract the scheme. We also |
| 591 // handle the case where there is no scheme. |
| 592 if (ExtractScheme(&spec[scheme_begin], spec_len - scheme_begin, |
| 593 &parsed->scheme)) { |
| 594 // Offset the results since we gave ExtractScheme a substring. |
| 595 parsed->scheme.begin += scheme_begin; |
| 596 } else { |
| 597 // No scheme case. |
| 598 parsed->scheme.reset(); |
| 599 } |
| 600 } |
| 601 |
| 567 // Converts a port number in a string to an integer. We'd like to just call | 602 // Converts a port number in a string to an integer. We'd like to just call |
| 568 // sscanf but our input is not NULL-terminated, which sscanf requires. Instead, | 603 // sscanf but our input is not NULL-terminated, which sscanf requires. Instead, |
| 569 // we copy the digits to a small stack buffer (since we know the maximum number | 604 // we copy the digits to a small stack buffer (since we know the maximum number |
| 570 // of digits in a valid port number) that we can NULL terminate. | 605 // of digits in a valid port number) that we can NULL terminate. |
| 571 template<typename CHAR> | 606 template<typename CHAR> |
| 572 int DoParsePort(const CHAR* spec, const Component& component) { | 607 int DoParsePort(const CHAR* spec, const Component& component) { |
| 573 // Easy success case when there is no port. | 608 // Easy success case when there is no port. |
| 574 const int kMaxDigits = 5; | 609 const int kMaxDigits = 5; |
| 575 if (!component.is_nonempty()) | 610 if (!component.is_nonempty()) |
| 576 return PORT_UNSPECIFIED; | 611 return PORT_UNSPECIFIED; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 } | 929 } |
| 895 | 930 |
| 896 void ParseMailtoURL(const char* url, int url_len, Parsed* parsed) { | 931 void ParseMailtoURL(const char* url, int url_len, Parsed* parsed) { |
| 897 DoParseMailtoURL(url, url_len, parsed); | 932 DoParseMailtoURL(url, url_len, parsed); |
| 898 } | 933 } |
| 899 | 934 |
| 900 void ParseMailtoURL(const base::char16* url, int url_len, Parsed* parsed) { | 935 void ParseMailtoURL(const base::char16* url, int url_len, Parsed* parsed) { |
| 901 DoParseMailtoURL(url, url_len, parsed); | 936 DoParseMailtoURL(url, url_len, parsed); |
| 902 } | 937 } |
| 903 | 938 |
| 939 void ParseNonStandardURL(const char* url, int url_len, Parsed* parsed) { |
| 940 DoParseNonStandardURL(url, url_len, parsed); |
| 941 } |
| 942 |
| 943 void ParseNonStandardURL(const base::char16* url, int url_len, Parsed* parsed) { |
| 944 DoParseNonStandardURL(url, url_len, parsed); |
| 945 } |
| 946 |
| 904 void ParsePathInternal(const char* spec, | 947 void ParsePathInternal(const char* spec, |
| 905 const Component& path, | 948 const Component& path, |
| 906 Component* filepath, | 949 Component* filepath, |
| 907 Component* query, | 950 Component* query, |
| 908 Component* ref) { | 951 Component* ref) { |
| 909 ParsePath(spec, path, filepath, query, ref); | 952 ParsePath(spec, path, filepath, query, ref); |
| 910 } | 953 } |
| 911 | 954 |
| 912 void ParsePathInternal(const base::char16* spec, | 955 void ParsePathInternal(const base::char16* spec, |
| 913 const Component& path, | 956 const Component& path, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 925 } | 968 } |
| 926 | 969 |
| 927 void ParseAfterScheme(const base::char16* spec, | 970 void ParseAfterScheme(const base::char16* spec, |
| 928 int spec_len, | 971 int spec_len, |
| 929 int after_scheme, | 972 int after_scheme, |
| 930 Parsed* parsed) { | 973 Parsed* parsed) { |
| 931 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 974 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
| 932 } | 975 } |
| 933 | 976 |
| 934 } // namespace url | 977 } // namespace url |
| OLD | NEW |