Skip to content

Commit

Permalink
Merge #30098: refactor: simplify FormatSubVersion using strprintf/Join
Browse files Browse the repository at this point in the history
12d8281 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 12d8281
  TheCharlatan:
    tACK 12d8281
  hebasto:
    ACK 12d8281, I have reviewed the code and it looks OK.
  tdb3:
    ACK for 12d8281.

Tree-SHA512: b9b965c4416a4c0c8727e3c4b40da4be04b14067200220492e9bed4fa35c1907fb5cdec2a30052b9e762f71da3d3cf042f43c96ab1f2523df5bb9920b44ea2a5
  • Loading branch information
fanquake committed May 15, 2024
2 parents 695d801 + 12d8281 commit 3d24189
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include <config/bitcoin-config.h> // IWYU pragma: keep

#include <clientversion.h>
#include <util/string.h>
#include <util/translation.h>

#include <tinyformat.h>

#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -64,19 +64,9 @@ std::string FormatFullVersion()
*/
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
{
std::ostringstream ss;
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);
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 comments_str;
if (!comments.empty()) comments_str = strprintf("(%s)", Join(comments, "; "));
return strprintf("/%s:%s%s/", name, FormatVersion(nClientVersion), comments_str);
}

std::string CopyrightHolders(const std::string& strPrefix)
Expand Down

0 comments on commit 3d24189

Please sign in to comment.