Index: url/url_parse.cc |
diff --git a/url/url_parse.cc b/url/url_parse.cc |
index 0d9c6dd1c9950cee13a8a1a4365bb59a9203a472..fb3c988930bef1bc968770291d0334739fceb51c 100644 |
--- a/url/url_parse.cc |
+++ b/url/url_parse.cc |
@@ -645,6 +645,44 @@ void DoExtractFileName(const CHAR* spec, |
} |
template<typename CHAR> |
+void DoExtractFileExtension(const CHAR* spec, |
+ const Component& path, |
+ Component* file_extension) { |
+ |
+ Component file_name; |
+ DoExtractFileName(spec, path, &file_name); |
+ |
+ // If there's no file specified in the path, there's no file extension |
+ if (!file_name.is_valid()) { |
+ file_extension->reset(); |
+ return; |
+ } |
+ |
+ // Search backwards for file delimiter '.' |
+ // We don't check the first character, because if the file name starts with |
+ // a '.' the rest of the file name is not typically considered a file |
+ // extension. |
+ int file_delimiter = -1; |
+ for (int i = file_name.end() - 1; i > file_name.begin; i--) { |
+ if (spec[i] == '.') { |
+ file_delimiter = i; |
+ break; |
+ } |
+ } |
+ |
+ // If we didn't find a file delimiter, there is no file extension |
+ if (file_delimiter == -1) { |
+ file_extension->reset(); |
+ return; |
+ } |
+ |
+ // Return everything in the filename following the delimiter |
+ *file_extension = MakeRange(file_delimiter+1, file_name.end()); |
+ return; |
+ |
+} |
+ |
+template<typename CHAR> |
bool DoExtractQueryKeyValue(const CHAR* spec, |
Component* query, |
Component* key, |
@@ -818,6 +856,18 @@ void ExtractFileName(const base::char16* url, |
DoExtractFileName(url, path, file_name); |
} |
+void ExtractFileExtension(const char* url, |
+ const Component& path, |
+ Component* file_extension) { |
+ DoExtractFileExtension(url, path, file_extension); |
+} |
+ |
+void ExtractFileExtension(const base::char16* url, |
+ const Component& path, |
+ Component* file_extension) { |
+ DoExtractFileExtension(url, path, file_extension); |
+} |
+ |
bool ExtractQueryKeyValue(const char* url, |
Component* query, |
Component* key, |