From 91921618c2e06bd0ed073b8efccd31a127c9012d Mon Sep 17 00:00:00 2001 From: AJR Date: Wed, 20 Jan 2021 17:46:03 -0500 Subject: Much more core std::string_view modernization - Remove corestr.h from emu.h; update a few source files to not use it at all - Change strtrimspace, strtrimrightspace and core_filename_extract_* to be pure functions taking a std::string_view by value and returning the same type - Change strmakeupper and strmakelower to be pure functions taking a std::string_view and constructing a std::string - Remove the string-modifying version of zippath_parent - Change tag-based lookup functions in device_t to take std::string_view instead of const std::string & or const char * - Remove the subdevice tag cache from device_t (since device finders are now recommended) and replace it with a map covering directly owned subdevices only - Move the working directory setup method out of device_image_interface (only the UI seems to actually use the full version of this) - Change output_manager to use std::string_view for output name arguments - Change core_options to accept std::string_view for most name and value arguments (return values are still C strings for now) - Change miscellaneous other functions to accept std::string_view arguments - Remove a few string accessor macros from romload.h - Remove many unnecessary c_str() calls from logging/error messages --- src/lib/util/corefile.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/lib/util/corefile.cpp') diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index cbe70bbf5fc..1149035045a 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1256,7 +1256,7 @@ core_file::core_file() // assumptions about path separators // ------------------------------------------------- -std::string core_filename_extract_base(const std::string &name, bool strip_extension) +std::string_view core_filename_extract_base(std::string_view name, bool strip_extension) { // find the start of the basename auto const start = std::find_if(name.rbegin(), name.rend(), &util::is_directory_separator); @@ -1269,8 +1269,7 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten ? std::next(chop_position) : name.rbegin(); - // copy the result into an string - return std::string(start.base(), end.base()); + return std::string_view(&*start.base(), end.base() - start.base()); } @@ -1278,13 +1277,13 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten // core_filename_extract_extension // ------------------------------------------------- -std::string core_filename_extract_extension(const std::string &filename, bool strip_period) +std::string_view core_filename_extract_extension(std::string_view filename, bool strip_period) { auto loc = filename.find_last_of('.'); - std::string result = loc != std::string::npos - ? filename.substr(loc + (strip_period ? 1 : 0)) - : ""; - return result; + if (loc != std::string_view::npos) + return filename.substr(loc + (strip_period ? 1 : 0)); + else + return std::string_view(); } @@ -1293,7 +1292,7 @@ std::string core_filename_extract_extension(const std::string &filename, bool st // filename end with the specified extension? // ------------------------------------------------- -bool core_filename_ends_with(const std::string &filename, const std::string &extension) +bool core_filename_ends_with(std::string_view filename, std::string_view extension) { auto namelen = filename.length(); auto extlen = extension.length(); -- cgit v1.2.3-70-g09d2