From 0e4cb93bc58d8b598bee9ff4ea6e5949853fadeb Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Mon, 11 Jul 2016 10:20:56 -0400 Subject: Adopting std::find() and std::find_if() in core_filename_extract_base() --- src/lib/util/corefile.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/lib/util/corefile.cpp') diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 725316b0dff..0fe87f15982 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1273,20 +1273,18 @@ core_file::core_file() std::string core_filename_extract_base(const std::string &name, bool strip_extension) { // find the start of the basename - auto start = name.end(); - while (start != name.begin() && !util::is_directory_separator(start[-1])) - start--; + auto const start = std::find_if(name.rbegin(), name.rend(), [](char c) { return util::is_directory_separator(c); }); // 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(); + auto const chop_position = strip_extension + ? std::find(name.rbegin(), start, '.') + : start; + auto const end = (chop_position != start) + ? chop_position + 1 + : name.rbegin(); // copy the result into an string - std::string result(start, end); + std::string result(start.base(), end.base()); return result; } -- cgit v1.2.3-70-g09d2