mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
This commit is contained in:
parent
c70f45ff44
commit
e5f09ea170
51 changed files with 282 additions and 261 deletions
14
AK/Error.h
14
AK/Error.h
|
@ -24,7 +24,19 @@ class Error {
|
|||
public:
|
||||
static Error from_errno(int code) { return Error(code); }
|
||||
static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); }
|
||||
static Error from_string_literal(StringView string_literal) { return Error(string_literal); }
|
||||
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
|
||||
|
||||
// NOTE: Prefer `from_string_literal` when directly typing out an error message:
|
||||
//
|
||||
// return Error::from_string_literal("Class: Some failure");
|
||||
//
|
||||
// If you need to return a static string based on a dynamic condition (like
|
||||
// picking an error from an array), then prefer `from_string_view` instead.
|
||||
template<size_t N>
|
||||
ALWAYS_INLINE static Error from_string_literal(char const (&string_literal)[N])
|
||||
{
|
||||
return from_string_view(StringView { string_literal, N - 1 });
|
||||
}
|
||||
|
||||
bool operator==(Error const& other) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue