summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/corefile.cpp
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-07-11 08:27:03 -0400
committer Nathan Woods <npwoods@mess.org>2016-07-11 08:27:03 -0400
commit2bd5932b42b56741dee27bf25bdac4158aaa6696 (patch)
tree64bf1363717e9d48cbdd735b2663990a986a5ea4 /src/lib/util/corefile.cpp
parent130e05cc4eb41119e56dee22aeb7f8126a8206ea (diff)
Deeper C++-ification
Diffstat (limited to 'src/lib/util/corefile.cpp')
-rw-r--r--src/lib/util/corefile.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp
index 01c539680a2..725316b0dff 100644
--- a/src/lib/util/corefile.cpp
+++ b/src/lib/util/corefile.cpp
@@ -1272,17 +1272,21 @@ core_file::core_file()
std::string core_filename_extract_base(const std::string &name, bool strip_extension)
{
- /* find the start of the name */
- const char *start = name.c_str() + name.length();
- while (start > name.c_str() && !util::is_directory_separator(start[-1]))
+ // find the start of the basename
+ auto start = name.end();
+ while (start != name.begin() && !util::is_directory_separator(start[-1]))
start--;
- /* copy the rest into an astring */
- std::string result(start);
+ // find the end of the basename
+ auto chop_position = strip_extension
+ ? name.find_last_of('.')
+ : std::string::npos;
+ auto end = chop_position != std::string::npos
+ ? name.begin() + chop_position
+ : name.end();
- /* chop the extension if present */
- if (strip_extension)
- result = result.substr(0, result.find_last_of('.'));
+ // copy the result into an string
+ std::string result(start, end);
return result;
}