From 9cc8e876e412056ed22d364538f0da3d5d71946d Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sat, 11 Sep 2021 13:02:47 +0200 Subject: [PATCH 1/3] refactor: introduce single-separator split helper `SplitString` This helper uses spanparsing::Split internally and enables to replace all calls to boost::split where only a single separator is passed. Co-authored-by: Martin Ankerl Co-authored-by: MarcoFalke --- src/bitcoin-tx.cpp | 17 +++++------------ src/chainparams.cpp | 7 ++----- src/rest.cpp | 13 ++++--------- src/rpc/server.cpp | 6 ++---- src/rpc/util.cpp | 9 ++------- src/test/fuzz/script_assets_test_minimizer.cpp | 5 ++--- src/test/transaction_tests.cpp | 5 +---- src/torcontrol.cpp | 12 ++++++------ src/util/spanparsing.cpp | 16 ---------------- src/util/spanparsing.h | 17 ++++++++++++++++- src/util/string.h | 6 ++++++ src/wallet/rpc/backup.cpp | 5 +---- 12 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 0b40626595fdc..05f910e9cb3b4 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -31,8 +31,6 @@ #include #include -#include - static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; @@ -251,8 +249,7 @@ static T TrimAndParse(const std::string& int_str, const std::string& err) static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput) { - std::vector vStrInputParts; - boost::split(vStrInputParts, strInput, boost::is_any_of(":")); + std::vector vStrInputParts = SplitString(strInput, ':'); // separate TXID:VOUT in string if (vStrInputParts.size()<2) @@ -287,8 +284,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strInput) { // Separate into VALUE:ADDRESS - std::vector vStrInputParts; - boost::split(vStrInputParts, strInput, boost::is_any_of(":")); + std::vector vStrInputParts = SplitString(strInput, ':'); if (vStrInputParts.size() != 2) throw std::runtime_error("TX output missing or too many separators"); @@ -312,8 +308,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& strInput) { // Separate into VALUE:PUBKEY[:FLAGS] - std::vector vStrInputParts; - boost::split(vStrInputParts, strInput, boost::is_any_of(":")); + std::vector vStrInputParts = SplitString(strInput, ':'); if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3) throw std::runtime_error("TX output missing or too many separators"); @@ -356,8 +351,7 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput) { // Separate into VALUE:REQUIRED:NUMKEYS:PUBKEY1:PUBKEY2:....[:FLAGS] - std::vector vStrInputParts; - boost::split(vStrInputParts, strInput, boost::is_any_of(":")); + std::vector vStrInputParts = SplitString(strInput, ':'); // Check that there are enough parameters if (vStrInputParts.size()<3) @@ -460,8 +454,7 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strIn static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput) { // separate VALUE:SCRIPT[:FLAGS] - std::vector vStrInputParts; - boost::split(vStrInputParts, strInput, boost::is_any_of(":")); + std::vector vStrInputParts = SplitString(strInput, ':'); if (vStrInputParts.size() < 2) throw std::runtime_error("TX output missing separator"); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c65a816a5f4db..7a7c72ea2570f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -10,13 +10,11 @@ #include #include // for signet block challenge hash #include