Merge bitcoin/bitcoin#30098: refactor: simplify FormatSubVersion using strprintf/Join

12d82817bf refactor: simplify `FormatSubVersion` using strprintf/Join (Sebastian Falbesoner)

Pull request description:

  Rather than using std::ostringstream and manually joining the comments, use strprintf and our own `Join` helper.

ACKs for top commit:
  maflcko:
    utACK 12d82817bf
  TheCharlatan:
    tACK 12d82817bf
  hebasto:
    ACK 12d82817bf, I have reviewed the code and it looks OK.
  tdb3:
    ACK for 12d82817bf.

Tree-SHA512: b9b965c4416a4c0c8727e3c4b40da4be04b14067200220492e9bed4fa35c1907fb5cdec2a30052b9e762f71da3d3cf042f43c96ab1f2523df5bb9920b44ea2a5
This commit is contained in:
merge-script 2024-05-15 12:48:37 +08:00
commit 3d24189664
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -5,11 +5,11 @@
#include <config/bitcoin-config.h> // IWYU pragma: keep #include <config/bitcoin-config.h> // IWYU pragma: keep
#include <clientversion.h> #include <clientversion.h>
#include <util/string.h>
#include <util/translation.h> #include <util/translation.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -64,19 +64,9 @@ std::string FormatFullVersion()
*/ */
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments) std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
{ {
std::ostringstream ss; std::string comments_str;
ss << "/"; if (!comments.empty()) comments_str = strprintf("(%s)", Join(comments, "; "));
ss << name << ":" << FormatVersion(nClientVersion); return strprintf("/%s:%s%s/", name, FormatVersion(nClientVersion), comments_str);
if (!comments.empty())
{
std::vector<std::string>::const_iterator it(comments.begin());
ss << "(" << *it;
for(++it; it != comments.end(); ++it)
ss << "; " << *it;
ss << ")";
}
ss << "/";
return ss.str();
} }
std::string CopyrightHolders(const std::string& strPrefix) std::string CopyrightHolders(const std::string& strPrefix)