forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add util::Result multiple error and warning messages
Add util::Result support for returning warning messages and multiple errors, not just a single error string. This provides a way for functions to report errors and warnings in a standard way, and simplifies interfaces. The functionality is unit tested here, and put to use in followup PR bitcoin#25722
- Loading branch information
Showing
4 changed files
with
222 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2022 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <util/result.h> | ||
|
||
#include <algorithm> | ||
#include <initializer_list> | ||
#include <iterator> | ||
#include <util/translation.h> | ||
|
||
namespace util { | ||
namespace detail { | ||
bilingual_str JoinMessages(const std::vector<bilingual_str>& errors, const std::vector<bilingual_str>& warnings) | ||
{ | ||
bilingual_str result; | ||
for (const auto& messages : {errors, warnings}) { | ||
for (const auto& message : messages) { | ||
if (!result.empty()) result += Untranslated(" "); | ||
result += message; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
void MoveMessages(std::vector<bilingual_str>& src, std::vector<bilingual_str>& dest) | ||
{ | ||
dest.insert(dest.end(), std::make_move_iterator(src.begin()), std::make_move_iterator(src.end())); | ||
src.clear(); | ||
} | ||
} // namespace detail | ||
} // namespace util |
Oops, something went wrong.