Changeset View
Changeset View
Standalone View
Standalone View
src/util/string.h
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_UTIL_STRING_H | #ifndef BITCOIN_UTIL_STRING_H | ||||
#define BITCOIN_UTIL_STRING_H | #define BITCOIN_UTIL_STRING_H | ||||
#include <attributes.h> | #include <attributes.h> | ||||
#include <cstring> | #include <cstring> | ||||
#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 | ||||
* | * | ||||
* @param list The list to join | * @param list The list to join | ||||
* @param separator The separator | * @param separator The separator | ||||
* @param unary_op Apply this operator to each item in the list | * @param unary_op Apply this operator to each item in the list | ||||
*/ | */ | ||||
template <typename T, typename UnaryOp> | template <typename T, typename UnaryOp> | ||||
Show All 25 Lines |