Skip to content

Commit 32e2712

Browse files
util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD.
1 parent 22d9bae commit 32e2712

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/util/string.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#include <string>
1212
#include <vector>
1313

14+
NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v")
15+
{
16+
std::string::size_type front = str.find_first_not_of(pattern);
17+
if (front == std::string::npos) {
18+
return std::string();
19+
}
20+
std::string::size_type end = str.find_last_not_of(pattern);
21+
return str.substr(front, end - front + 1);
22+
}
23+
1424
/**
1525
* Join a list of items
1626
*

src/util/system.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <chainparamsbase.h>
99
#include <util/strencodings.h>
10+
#include <util/string.h>
1011
#include <util/translation.h>
1112

1213

@@ -679,16 +680,6 @@ fs::path GetConfigFile(const std::string& confPath)
679680
return AbsPathForConfigVal(fs::path(confPath), false);
680681
}
681682

682-
static std::string TrimString(const std::string& str, const std::string& pattern)
683-
{
684-
std::string::size_type front = str.find_first_not_of(pattern);
685-
if (front == std::string::npos) {
686-
return std::string();
687-
}
688-
std::string::size_type end = str.find_last_not_of(pattern);
689-
return str.substr(front, end - front + 1);
690-
}
691-
692683
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)
693684
{
694685
std::string str, prefix;

0 commit comments

Comments
 (0)