From 6a5ccd65c704253b7442b54064f5ba281c34fd26 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:49:14 +0300 Subject: [PATCH 1/3] scripted-diff: Rename JoinErrors in more general MakeUnorderedList -BEGIN VERIFY SCRIPT- sed -i -e 's/JoinErrors/MakeUnorderedList/' -- src/qt/bitcoin.cpp -END VERIFY SCRIPT- --- src/qt/bitcoin.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 89b5ec6f4a8..ababab31d35 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -144,7 +144,7 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans QApplication::installTranslator(&translator); } -static std::string JoinErrors(const std::vector& errors) +static std::string MakeUnorderedList(const std::vector& errors) { return Join(errors, "\n", [](const std::string& error) { return "- " + error; }); } @@ -158,13 +158,13 @@ static bool InitSettings() std::vector errors; if (!gArgs.ReadSettingsFile(&errors)) { bilingual_str error = _("Settings file could not be read"); - InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors)))); + InitError(Untranslated(strprintf("%s:\n%s\n", error.original, MakeUnorderedList(errors)))); QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Reset | QMessageBox::Abort); /*: Explanatory text shown on startup when the settings file cannot be read. Prompts user to make a choice between resetting or aborting. */ messagebox.setInformativeText(QObject::tr("Do you want to reset settings to default values, or to abort without making changes?")); - messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors))); + messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(errors))); messagebox.setTextFormat(Qt::PlainText); messagebox.setDefaultButton(QMessageBox::Reset); switch (messagebox.exec()) { @@ -180,14 +180,14 @@ static bool InitSettings() errors.clear(); if (!gArgs.WriteSettingsFile(&errors)) { bilingual_str error = _("Settings file could not be written"); - InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors)))); + InitError(Untranslated(strprintf("%s:\n%s\n", error.original, MakeUnorderedList(errors)))); QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Ok); /*: Explanatory text shown on startup when the settings file could not be written. Prompts user to check that we have the ability to write to the file. Explains that the user has the option of running without a settings file.*/ messagebox.setInformativeText(QObject::tr("A fatal error occured. Check that settings file is writable, or try running with -nosettings.")); - messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors))); + messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(errors))); messagebox.setTextFormat(Qt::PlainText); messagebox.setDefaultButton(QMessageBox::Ok); messagebox.exec(); From 77a90f03acd551bcc538f6728939cc2ed8c6a3c4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:51:57 +0300 Subject: [PATCH 2/3] refactor: Move MakeUnorderedList into util/string.h to make it reusable --- src/qt/bitcoin.cpp | 8 ++------ src/util/string.h | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index ababab31d35..09f453363d6 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -144,11 +145,6 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans QApplication::installTranslator(&translator); } -static std::string MakeUnorderedList(const std::vector& errors) -{ - return Join(errors, "\n", [](const std::string& error) { return "- " + error; }); -} - static bool InitSettings() { if (!gArgs.GetSettingsPath()) { @@ -186,7 +182,7 @@ static bool InitSettings() /*: Explanatory text shown on startup when the settings file could not be written. Prompts user to check that we have the ability to write to the file. Explains that the user has the option of running without a settings file.*/ - messagebox.setInformativeText(QObject::tr("A fatal error occured. Check that settings file is writable, or try running with -nosettings.")); + messagebox.setInformativeText(QObject::tr("A fatal error occurred. Check that settings file is writable, or try running with -nosettings.")); messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(errors))); messagebox.setTextFormat(Qt::PlainText); messagebox.setDefaultButton(QMessageBox::Ok); diff --git a/src/util/string.h b/src/util/string.h index b26facc5028..5617e4acc1b 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -64,6 +64,14 @@ inline std::string Join(const std::vector& list, const std::string& return Join(list, separator); } +/** + * Create an unordered multi-line list of items. + */ +inline std::string MakeUnorderedList(const std::vector& items) +{ + return Join(items, "\n", [](const std::string& item) { return "- " + item; }); +} + /** * Check if a string does not contain any embedded NUL (\0) characters */ From bb56486a170aacb355f4a973f0cd40ab3918a0cd Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:59:14 +0300 Subject: [PATCH 3/3] refactor: Reuse MakeUnorderedList where possible --- src/rpc/blockchain.cpp | 3 ++- src/util/system.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4956ee39e94..909019d7968 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1328,7 +1329,7 @@ static RPCHelpMan verifychain() "\nVerifies blockchain database.\n", { {"checklevel", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL)}, - strprintf("How thorough the block verification is:\n - %s", Join(CHECKLEVEL_DOC, "\n- "))}, + strprintf("How thorough the block verification is:\n%s", MakeUnorderedList(CHECKLEVEL_DOC))}, {"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS)}, "The number of blocks to check."}, }, RPCResult{ diff --git a/src/util/system.cpp b/src/util/system.cpp index 258ba2f2355..30d41038198 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -502,11 +502,11 @@ bool ArgsManager::InitSettings(std::string& error) std::vector 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;