summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-01-20 17:46:03 -0500
committer AJR <ajrhacker@users.noreply.github.com>2021-01-20 18:06:15 -0500
commit91921618c2e06bd0ed073b8efccd31a127c9012d (patch)
treed3958b32d8db82540cd31083766b22991eb8e8ae /src/lib
parentc691b79cce315acdfabe1901cb2b5a1e39957bc1 (diff)
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
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/corefile.cpp17
-rw-r--r--src/lib/util/corefile.h6
-rw-r--r--src/lib/util/corestr.cpp48
-rw-r--r--src/lib/util/corestr.h11
-rw-r--r--src/lib/util/hash.cpp16
-rw-r--r--src/lib/util/hash.h2
-rw-r--r--src/lib/util/options.cpp111
-rw-r--r--src/lib/util/options.h49
-rw-r--r--src/lib/util/zippath.cpp24
-rw-r--r--src/lib/util/zippath.h1
10 files changed, 154 insertions, 131 deletions
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();
diff --git a/src/lib/util/corefile.h b/src/lib/util/corefile.h
index a558a279324..6aaa8f609e1 100644
--- a/src/lib/util/corefile.h
+++ b/src/lib/util/corefile.h
@@ -157,13 +157,13 @@ constexpr bool is_directory_separator(char c)
/* ----- filename utilities ----- */
// extract the base part of a filename (remove extensions and paths)
-std::string core_filename_extract_base(const std::string &name, bool strip_extension = false);
+std::string_view core_filename_extract_base(std::string_view name, bool strip_extension = false);
// extracts the file extension from a filename
-std::string core_filename_extract_extension(const std::string &filename, bool strip_period = false);
+std::string_view core_filename_extract_extension(std::string_view filename, bool strip_period = false);
// true if the given filename ends with a particular 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);
#endif // MAME_LIB_UTIL_COREFILE_H
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp
index 1e89015d456..aff55470b13 100644
--- a/src/lib/util/corestr.cpp
+++ b/src/lib/util/corestr.cpp
@@ -11,6 +11,7 @@
#include "corestr.h"
#include <algorithm>
+#include <iterator>
#include <memory>
#include <cctype>
@@ -125,8 +126,6 @@ bool core_iswildstr(const char *sp)
std::string helpers
-------------------------------------------------*/
-#include <algorithm>
-
void strdelchr(std::string& str, char chr)
{
for (size_t i = 0; i < str.length(); i++)
@@ -147,10 +146,10 @@ void strreplacechr(std::string& str, char ch, char newch)
}
}
-static std::string &internal_strtrimspace(std::string& str, bool right_only)
+static std::string_view internal_strtrimspace(std::string_view str, bool right_only)
{
// identify the start
- std::string::iterator start = str.begin();
+ std::string_view::iterator start = str.begin();
if (!right_only)
{
start = std::find_if(
@@ -160,48 +159,49 @@ static std::string &internal_strtrimspace(std::string& str, bool right_only)
}
// identify the end
- std::string::iterator end = std::find_if(
+ std::string_view::iterator end = std::find_if(
str.rbegin(),
- std::string::reverse_iterator(start),
+ std::string_view::reverse_iterator(start),
[](char c) { return !isspace(uint8_t(c)); }).base();
// extract the string
- str = end > start
+ return end > start
? str.substr(start - str.begin(), end - start)
- : "";
- return str;
+ : std::string_view();
}
-std::string &strtrimspace(std::string& str)
+std::string_view strtrimspace(std::string_view str)
{
return internal_strtrimspace(str, false);
}
-std::string &strtrimrightspace(std::string& str)
+std::string_view strtrimrightspace(std::string_view str)
{
return internal_strtrimspace(str, true);
}
-std::string &strmakeupper(std::string& str)
+std::string strmakeupper(std::string_view str)
{
- std::transform(str.begin(), str.end(), str.begin(), ::toupper);
- return str;
+ std::string result;
+ std::transform(str.begin(), str.end(), std::back_inserter(result), ::toupper);
+ return result;
}
/**
- * @fn std::string &strmakelower(std::string& str)
+ * @fn std::string &strmakelower(std::string_view str)
*
- * @brief Changes the given string to lower case.
+ * @brief Returns a lower case version of the given string.
*
* @param [in,out] str The string to make lower case
*
- * @return A reference to the original std::string having been changed to lower case
+ * @return A new std::string having been changed to lower case
*/
-std::string &strmakelower(std::string& str)
+std::string strmakelower(std::string_view str)
{
- std::transform(str.begin(), str.end(), str.begin(), ::tolower);
- return str;
+ std::string result;
+ std::transform(str.begin(), str.end(), std::back_inserter(result), ::tolower);
+ return result;
}
/**
@@ -233,7 +233,7 @@ int strreplace(std::string &str, const std::string& search, const std::string& r
namespace util {
/**
- * @fn double edit_distance(std::u32string const &lhs, std::u32string const &rhs)
+ * @fn double edit_distance(std::u32string_view lhs, std::u32string_view rhs)
*
* @brief Compares strings and returns prefix-weighted similarity score (smaller is more similar).
*
@@ -243,7 +243,7 @@ namespace util {
* @return Similarity score ranging from 0.0 (totally dissimilar) to 1.0 (identical).
*/
-double edit_distance(std::u32string const &lhs, std::u32string const &rhs)
+double edit_distance(std::u32string_view lhs, std::u32string_view rhs)
{
// based on Jaro-Winkler distance
// TODO: this breaks if the lengths don't fit in a long int, but that's not a big limitation
@@ -251,8 +251,8 @@ double edit_distance(std::u32string const &lhs, std::u32string const &rhs)
constexpr double PREFIX_WEIGHT(0.1);
constexpr double PREFIX_THRESHOLD(0.7);
- std::u32string const &longer((lhs.length() >= rhs.length()) ? lhs : rhs);
- std::u32string const &shorter((lhs.length() < rhs.length()) ? lhs : rhs);
+ std::u32string_view const &longer((lhs.length() >= rhs.length()) ? lhs : rhs);
+ std::u32string_view const &shorter((lhs.length() < rhs.length()) ? lhs : rhs);
// find matches
long const range((std::max)(long(longer.length() / 2) - 1, 0L));
diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h
index de294c0665c..81b04eeebaf 100644
--- a/src/lib/util/corestr.h
+++ b/src/lib/util/corestr.h
@@ -14,6 +14,7 @@
#pragma once
#include <string>
+#include <string_view>
#include <cstring>
@@ -53,16 +54,16 @@ bool core_iswildstr(const char *sp);
void strdelchr(std::string& str, char chr);
void strreplacechr(std::string& str, char ch, char newch);
-std::string &strtrimspace(std::string& str);
-std::string &strtrimrightspace(std::string& str);
-std::string &strmakeupper(std::string& str);
-std::string &strmakelower(std::string& str);
+[[nodiscard]] std::string_view strtrimspace(std::string_view str);
+[[nodiscard]] std::string_view strtrimrightspace(std::string_view str);
+[[nodiscard]] std::string strmakeupper(std::string_view str);
+[[nodiscard]] std::string strmakelower(std::string_view str);
int strreplace(std::string &str, const std::string& search, const std::string& replace);
namespace util {
// based on Jaro-Winkler distance - returns value from 0.0 (totally dissimilar) to 1.0 (identical)
-double edit_distance(std::u32string const &lhs, std::u32string const &rhs);
+double edit_distance(std::u32string_view lhs, std::u32string_view rhs);
} // namespace util
diff --git a/src/lib/util/hash.cpp b/src/lib/util/hash.cpp
index 5f2fd6f267a..a521e737192 100644
--- a/src/lib/util/hash.cpp
+++ b/src/lib/util/hash.cpp
@@ -11,7 +11,6 @@
***************************************************************************/
#include "hash.h"
-#include "corestr.h"
#include <cassert>
#include <cctype>
@@ -45,7 +44,7 @@ hash_collection::hash_collection()
}
-hash_collection::hash_collection(const char *string)
+hash_collection::hash_collection(std::string_view string)
: m_has_crc32(false),
m_has_sha1(false),
m_creator(nullptr)
@@ -237,7 +236,13 @@ std::string hash_collection::macro_string() const
buffer.append("NO_DUMP ");
if (flag(FLAG_BAD_DUMP))
buffer.append("BAD_DUMP ");
- strtrimspace(buffer);
+
+ // remove trailing space
+ if (!buffer.empty())
+ {
+ assert(buffer.back() == ' ');
+ buffer = buffer.substr(0, buffer.length() - 1);
+ }
return buffer;
}
@@ -264,7 +269,10 @@ std::string hash_collection::attribute_string() const
buffer.append("status=\"nodump\"");
if (flag(FLAG_BAD_DUMP))
buffer.append("status=\"baddump\"");
- strtrimspace(buffer);
+
+ // remove trailing space
+ if (!buffer.empty() && buffer.back() == ' ')
+ buffer = buffer.substr(0, buffer.length() - 1);
return buffer;
}
diff --git a/src/lib/util/hash.h b/src/lib/util/hash.h
index 891f8f3c44b..b13ac5556ae 100644
--- a/src/lib/util/hash.h
+++ b/src/lib/util/hash.h
@@ -56,7 +56,7 @@ public:
// construction/destruction
hash_collection();
- hash_collection(const char *string);
+ hash_collection(std::string_view string);
hash_collection(const hash_collection &src);
~hash_collection();
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp
index 7aa8817f580..e1674a88fe1 100644
--- a/src/lib/util/options.cpp
+++ b/src/lib/util/options.cpp
@@ -10,6 +10,7 @@
#include "options.h"
+#include "corefile.h"
#include "corestr.h"
#include "osdcomm.h"
@@ -55,17 +56,19 @@ const char *const core_options::s_option_unadorned[MAX_UNADORNED_OPTIONS] =
namespace
{
- void trim_spaces_and_quotes(std::string &data)
+ std::string_view trim_spaces_and_quotes(std::string_view data)
{
// trim any whitespace
- strtrimspace(data);
+ data = strtrimspace(data);
// trim quotes
- if (data.find_first_of('"') == 0 && data.find_last_of('"') == data.length() - 1)
+ if (data.length() >= 2 && data.front() == '"' && data.back() == '"')
{
- data.erase(0, 1);
- data.erase(data.length() - 1, 1);
+ data.remove_prefix(1);
+ data.remove_suffix(1);
}
+
+ return data;
}
};
@@ -451,11 +454,7 @@ void core_options::add_entry(entry::shared_ptr &&entry, const char *after_header
for (const std::string &name : entry->names())
{
// append the entry
- add_to_entry_map(std::string(name), entry);
-
- // for booleans, add the "-noXYZ" option as well
- if (entry->type() == option_type::BOOLEAN)
- add_to_entry_map(std::string("no") + name, entry);
+ add_to_entry_map(name, entry);
}
// and add the entry to the vector
@@ -468,13 +467,13 @@ void core_options::add_entry(entry::shared_ptr &&entry, const char *after_header
// map
//-------------------------------------------------
-void core_options::add_to_entry_map(std::string &&name, entry::shared_ptr &entry)
+void core_options::add_to_entry_map(const std::string &name, entry::shared_ptr &entry)
{
// it is illegal to call this method for something that already exists
assert(m_entrymap.find(name) == m_entrymap.end());
// append the entry
- m_entrymap.emplace(std::make_pair(name, entry::weak_ptr(entry)));
+ m_entrymap.emplace(std::make_pair(std::string_view(name), entry::weak_ptr(entry)));
}
@@ -493,26 +492,39 @@ void core_options::add_entry(const options_entry &opt, bool override_existing)
{
// first extract any range
std::string namestr(opt.name);
- int lparen = namestr.find_first_of('(', 0);
- int dash = namestr.find_first_of('-', lparen + 1);
- int rparen = namestr.find_first_of(')', dash + 1);
- if (lparen != -1 && dash != -1 && rparen != -1)
+ std::string::size_type lparen = namestr.find_first_of('(', 0);
+ if (lparen != std::string::npos)
{
- strtrimspace(minimum.assign(namestr.substr(lparen + 1, dash - (lparen + 1))));
- strtrimspace(maximum.assign(namestr.substr(dash + 1, rparen - (dash + 1))));
- namestr.erase(lparen, rparen + 1 - lparen);
+ std::string::size_type dash = namestr.find_first_of('-', lparen + 1);
+ if (dash != std::string::npos)
+ {
+ std::string::size_type rparen = namestr.find_first_of(')', dash + 1);
+ if (rparen != std::string::npos)
+ {
+ minimum.assign(strtrimspace(std::string_view(&namestr[lparen + 1], dash - (lparen + 1))));
+ maximum.assign(strtrimspace(std::string_view(&namestr[dash + 1], rparen - (dash + 1))));
+ namestr.erase(lparen, rparen + 1 - lparen);
+ }
+ }
}
// then chop up any semicolon-separated names
- size_t semi;
+ std::string::size_type semi;
while ((semi = namestr.find_first_of(';')) != std::string::npos)
{
names.push_back(namestr.substr(0, semi));
+
+ // for booleans, add the "-noXYZ" option as well
+ if (opt.type == option_type::BOOLEAN)
+ names.push_back(std::string("no") + names.back());
+
namestr.erase(0, semi + 1);
}
// finally add the last item
names.push_back(std::move(namestr));
+ if (opt.type == option_type::BOOLEAN)
+ names.push_back(std::string("no") + names.back());
}
// we might be called with an existing entry
@@ -597,10 +609,12 @@ void core_options::add_entries(const options_entry *entrylist, bool override_exi
// of an option
//-------------------------------------------------
-void core_options::set_default_value(const char *name, const char *defvalue)
+void core_options::set_default_value(std::string_view name, std::string &&defvalue)
{
// update the data and default data
- get_entry(name)->set_default_value(defvalue);
+ auto entry = get_entry(name);
+ assert(entry != nullptr);
+ entry->set_default_value(std::move(defvalue));
}
@@ -609,10 +623,12 @@ void core_options::set_default_value(const char *name, const char *defvalue)
// of an option
//-------------------------------------------------
-void core_options::set_description(const char *name, const char *description)
+void core_options::set_description(std::string_view name, const char *description)
{
// update the data and default data
- get_entry(name)->set_description(description);
+ auto entry = get_entry(name);
+ assert(entry != nullptr);
+ entry->set_description(description);
}
@@ -677,7 +693,7 @@ void core_options::parse_command_line(const std::vector<std::string> &args, int
continue;
// get the data for this argument, special casing booleans
- std::string newdata;
+ std::string_view newdata;
if (curentry->type() == option_type::BOOLEAN)
{
newdata = (strncmp(&curarg[1], "no", 2) == 0) ? "0" : "1";
@@ -696,7 +712,7 @@ void core_options::parse_command_line(const std::vector<std::string> &args, int
}
// set the new data
- do_set_value(*curentry, std::move(newdata), priority, error_stream, condition);
+ do_set_value(*curentry, newdata, priority, error_stream, condition);
}
// did we have any errors that may need to be aggregated?
@@ -770,9 +786,7 @@ void core_options::parse_ini_file(util::core_file &inifile, int priority, bool i
}
// set the new data
- std::string data = optiondata;
- trim_spaces_and_quotes(data);
- do_set_value(*curentry, std::move(data), priority, error_stream, condition);
+ do_set_value(*curentry, trim_spaces_and_quotes(optiondata), priority, error_stream, condition);
}
// did we have any errors that may need to be aggregated?
@@ -925,7 +939,7 @@ std::string core_options::output_help() const
// value - return the raw option value
//-------------------------------------------------
-const char *core_options::value(const char *option) const noexcept
+const char *core_options::value(std::string_view option) const noexcept
{
auto const entry = get_entry(option);
return entry ? entry->value() : nullptr;
@@ -936,7 +950,7 @@ const char *core_options::value(const char *option) const noexcept
// description - return description of option
//-------------------------------------------------
-const char *core_options::description(const char *option) const noexcept
+const char *core_options::description(std::string_view option) const noexcept
{
auto const entry = get_entry(option);
return entry ? entry->description() : nullptr;
@@ -947,7 +961,7 @@ const char *core_options::description(const char *option) const noexcept
// value - return the option value as an integer
//-------------------------------------------------
-int core_options::int_value(const char *option) const
+int core_options::int_value(std::string_view option) const
{
char const *const data = value(option);
if (!data)
@@ -966,7 +980,7 @@ int core_options::int_value(const char *option) const
// value - return the option value as a float
//-------------------------------------------------
-float core_options::float_value(const char *option) const
+float core_options::float_value(std::string_view option) const
{
char const *const data = value(option);
if (!data)
@@ -989,22 +1003,29 @@ float core_options::float_value(const char *option) const
// set_value - set the raw option value
//-------------------------------------------------
-void core_options::set_value(const std::string &name, const std::string &value, int priority)
+void core_options::set_value(std::string_view name, std::string_view value, int priority)
+{
+ set_value(name, std::string(value), priority);
+}
+
+void core_options::set_value(std::string_view name, const char *value, int priority)
{
set_value(name, std::string(value), priority);
}
-void core_options::set_value(const std::string &name, std::string &&value, int priority)
+void core_options::set_value(std::string_view name, std::string &&value, int priority)
{
- get_entry(name)->set_value(std::move(value), priority);
+ auto entry = get_entry(name);
+ assert(entry != nullptr);
+ entry->set_value(std::move(value), priority);
}
-void core_options::set_value(const std::string &name, int value, int priority)
+void core_options::set_value(std::string_view name, int value, int priority)
{
set_value(name, util::string_format("%d", value), priority);
}
-void core_options::set_value(const std::string &name, float value, int priority)
+void core_options::set_value(std::string_view name, float value, int priority)
{
set_value(name, util::string_format("%f", value), priority);
}
@@ -1037,13 +1058,13 @@ void core_options::remove_entry(core_options::entry &delentry)
// do_set_value
//-------------------------------------------------
-void core_options::do_set_value(entry &curentry, std::string &&data, int priority, std::ostream &error_stream, condition_type &condition)
+void core_options::do_set_value(entry &curentry, std::string_view data, int priority, std::ostream &error_stream, condition_type &condition)
{
// this is called when parsing a command line or an INI - we want to catch the option_exception and write
// any exception messages to the error stream
try
{
- curentry.set_value(std::move(data), priority);
+ curentry.set_value(std::string(data), priority);
}
catch (options_warning_exception &ex)
{
@@ -1064,13 +1085,13 @@ void core_options::do_set_value(entry &curentry, std::string &&data, int priorit
// get_entry
//-------------------------------------------------
-core_options::entry::shared_const_ptr core_options::get_entry(const std::string &name) const noexcept
+core_options::entry::shared_const_ptr core_options::get_entry(std::string_view name) const noexcept
{
auto curentry = m_entrymap.find(name);
return (curentry != m_entrymap.end()) ? curentry->second.lock() : nullptr;
}
-core_options::entry::shared_ptr core_options::get_entry(const std::string &name) noexcept
+core_options::entry::shared_ptr core_options::get_entry(std::string_view name) noexcept
{
auto curentry = m_entrymap.find(name);
return (curentry != m_entrymap.end()) ? curentry->second.lock() : nullptr;
@@ -1081,9 +1102,11 @@ core_options::entry::shared_ptr core_options::get_entry(const std::string &name)
// set_value_changed_handler
//-------------------------------------------------
-void core_options::set_value_changed_handler(const std::string &name, std::function<void(const char *)> &&handler)
+void core_options::set_value_changed_handler(std::string_view name, std::function<void(const char *)> &&handler)
{
- get_entry(name)->set_value_changed_handler(std::move(handler));
+ auto entry = get_entry(name);
+ assert(entry != nullptr);
+ entry->set_value_changed_handler(std::move(handler));
}
diff --git a/src/lib/util/options.h b/src/lib/util/options.h
index fc742ceb6c9..9b43e771c51 100644
--- a/src/lib/util/options.h
+++ b/src/lib/util/options.h
@@ -11,14 +11,17 @@
#ifndef MAME_LIB_UTIL_OPTIONS_H
#define MAME_LIB_UTIL_OPTIONS_H
-#include "corefile.h"
+#include "strformat.h"
+
#include <algorithm>
+#include <exception>
#include <functional>
+#include <iosfwd>
#include <memory>
#include <unordered_map>
#include <sstream>
-#include <stdexcept>
#include <string>
+#include <string_view>
#include <utility>
#include <vector>
@@ -40,6 +43,7 @@ const int OPTION_PRIORITY_MAXIMUM = 255; // maximum priority
//**************************************************************************
struct options_entry;
+namespace util { class core_file; }
// exception thrown by core_options when an illegal request is made
class options_exception : public std::exception
@@ -146,7 +150,7 @@ public:
private:
void validate(const std::string &value);
- std::vector<std::string> m_names;
+ const std::vector<std::string> m_names;
int m_priority;
core_options::option_type m_type;
const char * m_description;
@@ -164,10 +168,10 @@ public:
// getters
const std::string &command() const noexcept { return m_command; }
const std::vector<std::string> &command_arguments() const noexcept { assert(!m_command.empty()); return m_command_arguments; }
- entry::shared_const_ptr get_entry(const std::string &name) const noexcept;
- entry::shared_ptr get_entry(const std::string &name) noexcept;
+ entry::shared_const_ptr get_entry(std::string_view name) const noexcept;
+ entry::shared_ptr get_entry(std::string_view name) noexcept;
const std::vector<entry::shared_ptr> &entries() const noexcept { return m_entries; }
- bool exists(const std::string &name) const noexcept { return get_entry(name) != nullptr; }
+ bool exists(std::string_view name) const noexcept { return get_entry(name) != nullptr; }
bool header_exists(const char *description) const noexcept;
// configuration
@@ -176,10 +180,12 @@ public:
void add_entry(std::vector<std::string> &&names, const char *description, option_type type, std::string &&default_value = "", std::string &&minimum = "", std::string &&maximum = "");
void add_header(const char *description);
void add_entries(const options_entry *entrylist, bool override_existing = false);
- void set_default_value(const char *name, const char *defvalue);
- void set_description(const char *name, const char *description);
+ void set_default_value(std::string_view name, std::string &&defvalue);
+ void set_default_value(std::string_view name, std::string_view defvalue) { set_default_value(name, std::string(defvalue)); }
+ void set_default_value(std::string_view name, const char *defvalue) { set_default_value(name, std::string(defvalue)); }
+ void set_description(std::string_view name, const char *description);
void remove_entry(entry &delentry);
- void set_value_changed_handler(const std::string &name, std::function<void(const char *)> &&handler);
+ void set_value_changed_handler(std::string_view name, std::function<void(const char *)> &&handler);
void revert(int priority_hi = OPTION_PRIORITY_MAXIMUM, int priority_lo = OPTION_PRIORITY_DEFAULT);
// parsing/input
@@ -192,17 +198,18 @@ public:
std::string output_help() const;
// reading
- const char *value(const char *option) const noexcept;
- const char *description(const char *option) const noexcept;
- bool bool_value(const char *option) const { return int_value(option) != 0; }
- int int_value(const char *option) const;
- float float_value(const char *option) const;
+ const char *value(std::string_view option) const noexcept;
+ const char *description(std::string_view option) const noexcept;
+ bool bool_value(std::string_view option) const { return int_value(option) != 0; }
+ int int_value(std::string_view option) const;
+ float float_value(std::string_view option) const;
// setting
- void set_value(const std::string &name, const std::string &value, int priority);
- void set_value(const std::string &name, std::string &&value, int priority);
- void set_value(const std::string &name, int value, int priority);
- void set_value(const std::string &name, float value, int priority);
+ void set_value(std::string_view name, std::string_view value, int priority);
+ void set_value(std::string_view name, const char *value, int priority);
+ void set_value(std::string_view name, std::string &&value, int priority);
+ void set_value(std::string_view name, int value, int priority);
+ void set_value(std::string_view name, float value, int priority);
// misc
static const char *unadorned(int x = 0) noexcept { return s_option_unadorned[std::min(x, MAX_UNADORNED_OPTIONS - 1)]; }
@@ -251,13 +258,13 @@ private:
};
// internal helpers
- void add_to_entry_map(std::string &&name, entry::shared_ptr &entry);
- void do_set_value(entry &curentry, std::string &&data, int priority, std::ostream &error_stream, condition_type &condition);
+ void add_to_entry_map(const std::string &name, entry::shared_ptr &entry);
+ void do_set_value(entry &curentry, std::string_view data, int priority, std::ostream &error_stream, condition_type &condition);
void throw_options_exception_if_appropriate(condition_type condition, std::ostringstream &error_stream);
// internal state
std::vector<entry::shared_ptr> m_entries; // canonical list of entries
- std::unordered_map<std::string, entry::weak_ptr> m_entrymap; // map for fast lookup
+ std::unordered_map<std::string_view, entry::weak_ptr> m_entrymap; // map for fast lookup
std::string m_command; // command found
std::vector<std::string> m_command_arguments; // command arguments
static const char *const s_option_unadorned[]; // array of unadorned option "names"
diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp
index 27e5f123576..01d708bf2e1 100644
--- a/src/lib/util/zippath.cpp
+++ b/src/lib/util/zippath.cpp
@@ -65,7 +65,7 @@ bool is_root(std::string_view path)
// 7-zip file
// -------------------------------------------------
-bool is_7z_file(std::string const &path)
+bool is_7z_file(std::string_view path)
{
return core_filename_ends_with(path, ".7z");
}
@@ -76,7 +76,7 @@ bool is_7z_file(std::string const &path)
// ZIP file
// -------------------------------------------------
-bool is_zip_file(std::string const &path)
+bool is_zip_file(std::string_view path)
{
return core_filename_ends_with(path, ".zip");
}
@@ -593,7 +593,7 @@ zippath_directory::~zippath_directory()
// zippath_parent - retrieves the parent directory
// -------------------------------------------------
-std::string &zippath_parent(std::string &dst, std::string_view path)
+std::string zippath_parent(std::string_view path)
{
// skip over trailing path separators
std::string_view::size_type pos = path.find_last_not_of(PATH_SEPARATOR);
@@ -603,23 +603,9 @@ std::string &zippath_parent(std::string &dst, std::string_view path)
pos = (pos > 0) ? pos - 1 : std::string_view::npos;
if (pos != std::string_view::npos)
- dst = std::string(path, 0, pos + 1);
+ return std::string(path, 0, pos + 1);
else
- dst = std::string();
- return dst;
-}
-
-
-
-// -------------------------------------------------
-// zippath_parent - retrieves the parent directory
-// -------------------------------------------------
-
-std::string zippath_parent(std::string_view path)
-{
- std::string result;
- zippath_parent(result, path);
- return result;
+ return std::string();
}
diff --git a/src/lib/util/zippath.h b/src/lib/util/zippath.h
index 6e0e4623996..1eb92aa1c1d 100644
--- a/src/lib/util/zippath.h
+++ b/src/lib/util/zippath.h
@@ -53,7 +53,6 @@ public:
// ----- path operations -----
// retrieves the parent directory
-std::string &zippath_parent(std::string &dst, std::string_view path);
std::string zippath_parent(std::string_view path);
// combines two paths