mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-11 15:19:19 +02:00
util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD.
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user