mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #16670: util: Add Join helper to join a list of strings
faebf6271467048dc8a9a0c526a0f8565023a966 rpc: Use Join helper in rpc/util (MarcoFalke) fa8cd6f9c13319baca467864661982a3dfb2320c util: Add Join helper to join a list of strings (MarcoFalke) Pull request description: We have a lot of enumerations in the code and sometimes those enumerations need to be mentioned in the RPC or command line documentation. Previously, each caller would have a couple of lines inline to join the strings or the joined string is hardcoded in the documentation. A helper to join strings would make code such as https://github.com/bitcoin/bitcoin/pull/16629#discussion_r315852446 less verbose and easier to read. Also, warnings commonly accumulate in complex RPCs, since a warning doesn't lead to an early return. A helper to join those warnings would make code such as https://github.com/bitcoin/bitcoin/pull/16394/files#r309324997 less verbose and easier to read. ACKs for top commit: practicalswift: ACK faebf6271467048dc8a9a0c526a0f8565023a966 Tree-SHA512: 80f2db86a05c63b686f510585c1c631250271a8958fd71fafaac91559ffd2ec25d609bf7d53412ba27f87eff5893ac9dd9c2f296fc0c73581556e1d6a734a36f
This commit is contained in:
parent
6d8e78a661
commit
c6df9aeb85
@ -11,8 +11,8 @@
|
||||
#include <script/signingprovider.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/system.h>
|
||||
#include <util/string.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <tuple>
|
||||
@ -738,11 +738,7 @@ std::string RPCArg::ToString(const bool oneline) const
|
||||
}
|
||||
case Type::OBJ:
|
||||
case Type::OBJ_USER_KEYS: {
|
||||
std::string res;
|
||||
for (size_t i = 0; i < m_inner.size();) {
|
||||
res += m_inner[i].ToStringObj(oneline);
|
||||
if (++i < m_inner.size()) res += ",";
|
||||
}
|
||||
const std::string res = Join(m_inner, ",", [&](const RPCArg& i) { return i.ToStringObj(oneline); });
|
||||
if (m_type == Type::OBJ) {
|
||||
return "{" + res + "}";
|
||||
} else {
|
||||
|
@ -8,18 +8,18 @@
|
||||
#include <hash.h> // For Hash()
|
||||
#include <key.h> // For CKey
|
||||
#include <sync.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
#include <util/getuniquepath.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/message.h> // For MessageSign(), MessageVerify(), MESSAGE_MAGIC
|
||||
#include <util/moneystr.h>
|
||||
#include <util/time.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/vector.h>
|
||||
#include <util/spanparsing.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/time.h>
|
||||
#include <util/vector.h>
|
||||
|
||||
#include <array>
|
||||
#include <stdint.h>
|
||||
@ -139,6 +139,12 @@ BOOST_AUTO_TEST_CASE(util_Join)
|
||||
BOOST_CHECK_EQUAL(Join({}, ", "), "");
|
||||
BOOST_CHECK_EQUAL(Join({"foo"}, ", "), "foo");
|
||||
BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", "), "foo, bar");
|
||||
|
||||
// Version with unary operator
|
||||
const auto op_upper = [](const std::string& s) { return ToUpper(s); };
|
||||
BOOST_CHECK_EQUAL(Join<std::string>({}, ", ", op_upper), "");
|
||||
BOOST_CHECK_EQUAL(Join<std::string>({"foo"}, ", ", op_upper), "FOO");
|
||||
BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_TrimString)
|
||||
|
Loading…
Reference in New Issue
Block a user