util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD.
This commit is contained in:
1 parent
22d9bae36f
commit
32e27129ff
2 files changed
+11
-10
No files matched your search
@@ -11,6 +11,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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
|
* Join a list of items
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-10
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <chainparamsbase.h>
|
#include <chainparamsbase.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -679,16 +680,6 @@ fs::path GetConfigFile(const std::string& confPath)
|
|||||||
return AbsPathForConfigVal(fs::path(confPath), false);
|
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)
|
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;
|
std::string str, prefix;
|
||||||
|
|||||||
Reference in new issue
Block a user