diff options
author | 2016-07-31 15:06:06 -0400 | |
---|---|---|
committer | 2016-07-31 15:06:06 -0400 | |
commit | a4f24a24d3ed131d75b407a96a44b7d7c5d68b65 (patch) | |
tree | 02784b2b06cfe2c05d3a6ac9e5dcfe5dbb6f6ffd /src/lib/util/corefile.cpp | |
parent | a0ce6c3b37050c1a765ae13babb109c729153989 (diff) |
This changes device_image_interface::filetype() to return 'const std::string &' instead of 'const char *'.
In the interests of removing burdens from client code, I also changed the following:
- filetype() will always return the file extension in lower case
- device_image_interface::filetype() will return the correct extension for files loaded as a part of softlists
- The code for extracting a file extension is now encapsulated in core_filename_extract_extension()
Client code has been updated
Diffstat (limited to 'src/lib/util/corefile.cpp')
-rw-r--r-- | src/lib/util/corefile.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 5fcd9e00239..22b67046150 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1266,11 +1266,11 @@ core_file::core_file() FILENAME UTILITIES ***************************************************************************/ -/*------------------------------------------------- - core_filename_extract_base - extract the base - name from a filename; note that this makes - assumptions about path separators --------------------------------------------------*/ +// ------------------------------------------------- +// core_filename_extract_base - extract the base +// name from a filename; note that this makes +// assumptions about path separators +// ------------------------------------------------- std::string core_filename_extract_base(const std::string &name, bool strip_extension) { @@ -1290,10 +1290,26 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten } -/*------------------------------------------------- - core_filename_ends_with - does the given - filename end with the specified extension? --------------------------------------------------*/ +// ------------------------------------------------- +// core_filename_extract_extension +// ------------------------------------------------- + +std::string core_filename_extract_extension(const std::string &filename, bool strip_period, bool normalize_to_lowercase) +{ + auto loc = filename.find_last_of('.'); + std::string result = loc != std::string::npos + ? filename.substr(loc + (strip_period ? 1 : 0)) + : ""; + if (normalize_to_lowercase) + std::transform(result.begin(), result.end(), result.begin(), ::tolower); + return result; +} + + +// ------------------------------------------------- +// core_filename_ends_with - does the given +// filename end with the specified extension? +// ------------------------------------------------- bool core_filename_ends_with(const std::string &filename, const std::string &extension) { |