mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge bitcoin/bitcoin#22953: refactor: introduce single-separator split helper (boost::split replacement)
a62e84438dfuzz: add `SplitString` fuzz target (MarcoFalke)4fad7e46d9test: add unit tests for `SplitString` helper (Kiminuo)9cc8e876e4refactor: introduce single-separator split helper `SplitString` (Sebastian Falbesoner) Pull request description: This PR adds a simple string split helper `SplitString` that takes use of the spanparsing `Split` function that was first introduced in #13697 (commitfe8a7dcd78). This enables to replace most calls to `boost::split`, in the cases where only a single separator character is used. Note that while previous attempts to replace `boost::split` were controversial (e.g. #13751), this one has a trivial implementation: it merely uses an internal helper (that is unit tested and in regular use with output descriptiors) and converts its result from spans to strings. As a drawback though, not all `boost::split` instances can be tackled. As a possible optimization, one could return a vector of `std::string_view`s (available since C++17) instead of strings, to avoid copies. This would need more carefulness on the caller sites though, to avoid potential lifetime issues, and it's probably not worth it, considering that none of the places where strings are split are really performance-critical. ACKs for top commit: martinus: Code review ACKa62e84438d. Ran all tests. I also like that with `boost::split` it was not obvious that the resulting container was cleared, and with `SplitString` API that's obvious. Tree-SHA512: 10cb22619ebe46831b1f8e83584a89381a036b54c88701484ac00743e2a62cfe52c9f3ecdbb2d0815e536c99034558277cc263600ec3f3588b291c07eef8ed24
This commit is contained in:
@@ -24,9 +24,7 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
@@ -347,8 +345,8 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
|
||||
for (const auto& line : reply.lines) {
|
||||
if (0 == line.compare(0, 20, "net/listeners/socks=")) {
|
||||
const std::string port_list_str = line.substr(20);
|
||||
std::vector<std::string> port_list;
|
||||
boost::split(port_list, port_list_str, boost::is_any_of(" "));
|
||||
std::vector<std::string> port_list = SplitString(port_list_str, ' ');
|
||||
|
||||
for (auto& portstr : port_list) {
|
||||
if (portstr.empty()) continue;
|
||||
if ((portstr[0] == '"' || portstr[0] == '\'') && portstr.size() >= 2 && (*portstr.rbegin() == portstr[0])) {
|
||||
@@ -542,8 +540,10 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
|
||||
if (l.first == "AUTH") {
|
||||
std::map<std::string,std::string> m = ParseTorReplyMapping(l.second);
|
||||
std::map<std::string,std::string>::iterator i;
|
||||
if ((i = m.find("METHODS")) != m.end())
|
||||
boost::split(methods, i->second, boost::is_any_of(","));
|
||||
if ((i = m.find("METHODS")) != m.end()) {
|
||||
std::vector<std::string> m_vec = SplitString(i->second, ',');
|
||||
methods = std::set<std::string>(m_vec.begin(), m_vec.end());
|
||||
}
|
||||
if ((i = m.find("COOKIEFILE")) != m.end())
|
||||
cookiefile = i->second;
|
||||
} else if (l.first == "VERSION") {
|
||||
|
||||
Reference in New Issue
Block a user