diff options
author | fanquake <fanquake@gmail.com> | 2021-08-11 09:56:22 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-08-11 09:56:34 +0800 |
commit | c3545a7396787c1d649f2d12fcb380b714cab6b2 (patch) | |
tree | 1e62d8248c4d4b1e9a74df227c9a37a527f2c10b /src/util | |
parent | 0b5344b0d18788e011f2d4a279c8c12a29f1428a (diff) | |
parent | bb56486a170aacb355f4a973f0cd40ab3918a0cd (diff) |
Merge bitcoin/bitcoin#22653: refactor: Rename JoinErrors and re-use it
bb56486a170aacb355f4a973f0cd40ab3918a0cd refactor: Reuse MakeUnorderedList where possible (Hennadii Stepanov)
77a90f03acd551bcc538f6728939cc2ed8c6a3c4 refactor: Move MakeUnorderedList into util/string.h to make it reusable (Hennadii Stepanov)
6a5ccd65c704253b7442b54064f5ba281c34fd26 scripted-diff: Rename JoinErrors in more general MakeUnorderedList (Hennadii Stepanov)
Pull request description:
A nice `JoinErrors` utility function was introduced in https://github.com/bitcoin-core/gui/pull/379 by Russell Yanofsky.
This PR renames this function and re-uses it across the code base.
ACKs for top commit:
Zero-1729:
Concept ACK bb56486a170aacb355f4a973f0cd40ab3918a0cd
theStack:
Code-review ACK bb56486a170aacb355f4a973f0cd40ab3918a0cd
Talkless:
utACK bb56486a170aacb355f4a973f0cd40ab3918a0cd
ryanofsky:
Code review ACK bb56486a170aacb355f4a973f0cd40ab3918a0cd. Nice deduping, thanks for this!
Tree-SHA512: 6bdbfa61f2ffa69e075f46b733f247c6d5b8486779a1dac064285a199a4bb8bc5ef44eaee37086305646b5c88eb6a11990883219a4a9140a5117ee21ed529bb9
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/string.h | 8 | ||||
-rw-r--r-- | src/util/system.cpp | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/util/string.h b/src/util/string.h index b26facc502..5617e4acc1 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -65,6 +65,14 @@ inline std::string Join(const std::vector<std::string>& list, const std::string& } /** + * Create an unordered multi-line list of items. + */ +inline std::string MakeUnorderedList(const std::vector<std::string>& items) +{ + return Join(items, "\n", [](const std::string& item) { return "- " + item; }); +} + +/** * Check if a string does not contain any embedded NUL (\0) characters */ [[nodiscard]] inline bool ValidAsCString(const std::string& str) noexcept diff --git a/src/util/system.cpp b/src/util/system.cpp index 258ba2f235..30d4103819 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -502,11 +502,11 @@ bool ArgsManager::InitSettings(std::string& error) std::vector<std::string> errors; if (!ReadSettingsFile(&errors)) { - error = strprintf("Failed loading settings file:\n- %s\n", Join(errors, "\n- ")); + error = strprintf("Failed loading settings file:\n%s\n", MakeUnorderedList(errors)); return false; } if (!WriteSettingsFile(&errors)) { - error = strprintf("Failed saving settings file:\n- %s\n", Join(errors, "\n- ")); + error = strprintf("Failed saving settings file:\n%s\n", MakeUnorderedList(errors)); return false; } return true; |