summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author npwoods <npwoods@alumni.cmu.edu>2017-06-23 19:46:58 -0400
committer Vas Crabb <cuavas@users.noreply.github.com>2017-06-24 09:46:58 +1000
commit2af3233101b109a6ebcb1087d2c47ebce3c4c978 (patch)
tree3ec211a11853626cfd00a13f3148ff5cc8cf96f5 /src/lib
parentf1c043d18c6882930b4c00877c5d1773c527f998 (diff)
Changed a few 'const char *' ==> 'const std::string &' in the MAME debugger (#2170)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/corestr.cpp44
-rw-r--r--src/lib/util/corestr.h1
2 files changed, 30 insertions, 15 deletions
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp
index 66b12f6ee04..c8775f1cec0 100644
--- a/src/lib/util/corestr.cpp
+++ b/src/lib/util/corestr.cpp
@@ -171,27 +171,41 @@ void strreplacechr(std::string& str, char ch, char newch)
}
}
-std::string strtrimspace(std::string& str)
+static std::string internal_strtrimspace(std::string& str, bool right_only)
{
- int start = 0;
- for (auto & elem : str)
- {
- if (!isspace(uint8_t(elem))) break;
- start++;
- }
- int end = str.length();
- if (end > 0)
+ // identify the start
+ std::string::iterator start = str.begin();
+ if (!right_only)
{
- for (size_t i = str.length() - 1; i > 0; i--)
- {
- if (!isspace(uint8_t(str[i]))) break;
- end--;
- }
+ start = std::find_if(
+ str.begin(),
+ str.end(),
+ [](char c) { return !isspace(uint8_t(c)); });
}
- str = str.substr(start, end-start);
+
+ // identify the end
+ std::string::iterator end = std::find_if(
+ str.rbegin(),
+ std::string::reverse_iterator(start),
+ [](char c) { return !isspace(uint8_t(c)); }).base();
+
+ // extract the string
+ str = end > start
+ ? str.substr(start - str.begin(), end - start)
+ : "";
return str;
}
+std::string strtrimspace(std::string& str)
+{
+ return internal_strtrimspace(str, false);
+}
+
+std::string strtrimrightspace(std::string& str)
+{
+ return internal_strtrimspace(str, true);
+}
+
std::string strmakeupper(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h
index 9a9bce23e99..d31c1e5f8df 100644
--- a/src/lib/util/corestr.h
+++ b/src/lib/util/corestr.h
@@ -67,6 +67,7 @@ int strcatvprintf(std::string &str, const char *format, va_list args);
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);
int strreplace(std::string &str, const std::string& search, const std::string& replace);