summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/corefile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/corefile.cpp')
-rw-r--r--src/lib/util/corefile.cpp34
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)
{