Error: Add AddPrefix()/AddSuffix()

This commit is contained in:
Stenzek 2024-02-25 18:17:25 +10:00
parent df3517f19b
commit 18ba2032ad
No known key found for this signature in database
2 changed files with 28 additions and 1 deletions

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "error.h"
@ -232,6 +232,28 @@ Error Error::CreateHResult(long err)
#endif
void Error::AddPrefix(std::string_view prefix)
{
m_description.insert(0, prefix);
}
void Error::AddSuffix(std::string_view suffix)
{
m_description.append(suffix);
}
void Error::AddPrefix(Error* errptr, std::string_view prefix)
{
if (errptr)
errptr->AddPrefix(prefix);
}
void Error::AddSuffix(Error* errptr, std::string_view prefix)
{
if (errptr)
errptr->AddSuffix(prefix);
}
Error& Error::operator=(const Error& e) = default;
Error& Error::operator=(Error&& e) = default;

View File

@ -89,6 +89,11 @@ public:
Error::SetString(errptr, fmt::vformat(fmt, fmt::make_format_args(args...)));
}
void AddPrefix(std::string_view prefix);
void AddSuffix(std::string_view suffix);
static void AddPrefix(Error* errptr, std::string_view prefix);
static void AddSuffix(Error* errptr, std::string_view prefix);
Error& operator=(const Error& e);
Error& operator=(Error&& e);
bool operator==(const Error& e) const;