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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 638 } |
639 } | 639 } |
640 | 640 |
641 // No slash found, this means the input was degenerate (generally paths | 641 // No slash found, this means the input was degenerate (generally paths |
642 // will start with a slash). Let's call everything the file name. | 642 // will start with a slash). Let's call everything the file name. |
643 *file_name = MakeRange(path.begin, file_end); | 643 *file_name = MakeRange(path.begin, file_end); |
644 return; | 644 return; |
645 } | 645 } |
646 | 646 |
647 template<typename CHAR> | 647 template<typename CHAR> |
| 648 void DoExtractFileExtension(const CHAR* spec, |
| 649 const Component& path, |
| 650 Component* file_extension) { |
| 651 |
| 652 Component file_name; |
| 653 DoExtractFileName(spec, path, &file_name); |
| 654 |
| 655 // If there's no file specified in the path, there's no file extension |
| 656 if (!file_name.is_valid()) { |
| 657 file_extension->reset(); |
| 658 return; |
| 659 } |
| 660 |
| 661 // Search backwards for file delimiter '.' |
| 662 // We don't check the first character, because if the file name starts with |
| 663 // a '.' the rest of the file name is not typically considered a file |
| 664 // extension. |
| 665 int file_delimiter = -1; |
| 666 for (int i = file_name.end() - 1; i > file_name.begin; i--) { |
| 667 if (spec[i] == '.') { |
| 668 file_delimiter = i; |
| 669 break; |
| 670 } |
| 671 } |
| 672 |
| 673 // If we didn't find a file delimiter, there is no file extension |
| 674 if (file_delimiter == -1) { |
| 675 file_extension->reset(); |
| 676 return; |
| 677 } |
| 678 |
| 679 // Return everything in the filename following the delimiter |
| 680 *file_extension = MakeRange(file_delimiter+1, file_name.end()); |
| 681 return; |
| 682 |
| 683 } |
| 684 |
| 685 template<typename CHAR> |
648 bool DoExtractQueryKeyValue(const CHAR* spec, | 686 bool DoExtractQueryKeyValue(const CHAR* spec, |
649 Component* query, | 687 Component* query, |
650 Component* key, | 688 Component* key, |
651 Component* value) { | 689 Component* value) { |
652 if (!query->is_nonempty()) | 690 if (!query->is_nonempty()) |
653 return false; | 691 return false; |
654 | 692 |
655 int start = query->begin; | 693 int start = query->begin; |
656 int cur = start; | 694 int cur = start; |
657 int end = query->end(); | 695 int end = query->end(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 Component* file_name) { | 849 Component* file_name) { |
812 DoExtractFileName(url, path, file_name); | 850 DoExtractFileName(url, path, file_name); |
813 } | 851 } |
814 | 852 |
815 void ExtractFileName(const base::char16* url, | 853 void ExtractFileName(const base::char16* url, |
816 const Component& path, | 854 const Component& path, |
817 Component* file_name) { | 855 Component* file_name) { |
818 DoExtractFileName(url, path, file_name); | 856 DoExtractFileName(url, path, file_name); |
819 } | 857 } |
820 | 858 |
| 859 void ExtractFileExtension(const char* url, |
| 860 const Component& path, |
| 861 Component* file_extension) { |
| 862 DoExtractFileExtension(url, path, file_extension); |
| 863 } |
| 864 |
| 865 void ExtractFileExtension(const base::char16* url, |
| 866 const Component& path, |
| 867 Component* file_extension) { |
| 868 DoExtractFileExtension(url, path, file_extension); |
| 869 } |
| 870 |
821 bool ExtractQueryKeyValue(const char* url, | 871 bool ExtractQueryKeyValue(const char* url, |
822 Component* query, | 872 Component* query, |
823 Component* key, | 873 Component* key, |
824 Component* value) { | 874 Component* value) { |
825 return DoExtractQueryKeyValue(url, query, key, value); | 875 return DoExtractQueryKeyValue(url, query, key, value); |
826 } | 876 } |
827 | 877 |
828 bool ExtractQueryKeyValue(const base::char16* url, | 878 bool ExtractQueryKeyValue(const base::char16* url, |
829 Component* query, | 879 Component* query, |
830 Component* key, | 880 Component* key, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 } | 964 } |
915 | 965 |
916 void ParseAfterScheme(const base::char16* spec, | 966 void ParseAfterScheme(const base::char16* spec, |
917 int spec_len, | 967 int spec_len, |
918 int after_scheme, | 968 int after_scheme, |
919 Parsed* parsed) { | 969 Parsed* parsed) { |
920 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 970 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
921 } | 971 } |
922 | 972 |
923 } // namespace url_parse | 973 } // namespace url_parse |
OLD | NEW |