aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2019-12-11 09:55:00 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2019-12-16 22:50:49 +0000
commit32e27129ff26c7cc10321652d5d2678876081983 (patch)
tree400fe56c9c3fff072a059f76d47ea16eab926d51 /src
parent22d9bae36f2a164acf35765231f1d93364c1c4a9 (diff)
downloadbitcoin-32e27129ff26c7cc10321652d5d2678876081983.tar.xz
util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD.
Diffstat (limited to 'src')
-rw-r--r--src/util/string.h10
-rw-r--r--src/util/system.cpp11
2 files changed, 11 insertions, 10 deletions
diff --git a/src/util/string.h b/src/util/string.h
index c6fa08e5b3..3db8fc8b98 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -11,6 +11,16 @@
#include <string>
#include <vector>
+NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v")
+{
+ std::string::size_type front = str.find_first_not_of(pattern);
+ if (front == std::string::npos) {
+ return std::string();
+ }
+ std::string::size_type end = str.find_last_not_of(pattern);
+ return str.substr(front, end - front + 1);
+}
+
/**
* Join a list of items
*
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 563ff6a54b..95458672ed 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -7,6 +7,7 @@
#include <chainparamsbase.h>
#include <util/strencodings.h>
+#include <util/string.h>
#include <util/translation.h>
@@ -679,16 +680,6 @@ fs::path GetConfigFile(const std::string& confPath)
return AbsPathForConfigVal(fs::path(confPath), false);
}
-static std::string TrimString(const std::string& str, const std::string& pattern)
-{
- std::string::size_type front = str.find_first_not_of(pattern);
- if (front == std::string::npos) {
- return std::string();
- }
- std::string::size_type end = str.find_last_not_of(pattern);
- return str.substr(front, end - front + 1);
-}
-
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
{
std::string str, prefix;