1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +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:
sin-ack 2022-07-11 17:57:32 +00:00 committed by Andreas Kling
parent c70f45ff44
commit e5f09ea170
51 changed files with 282 additions and 261 deletions

View file

@ -211,7 +211,7 @@ struct CanonicalLanguageID {
if (segments.size() == ++index)
return language_id;
} else {
return Error::from_string_literal("Expected language subtag"sv);
return Error::from_string_literal("Expected language subtag");
}
if (Unicode::is_unicode_script_subtag(segments[index])) {
@ -228,7 +228,7 @@ struct CanonicalLanguageID {
while (index < segments.size()) {
if (!Unicode::is_unicode_variant_subtag(segments[index]))
return Error::from_string_literal("Expected variant subtag"sv);
return Error::from_string_literal("Expected variant subtag");
language_id.variants.append(unique_strings.ensure(segments[index++]));
}
@ -244,7 +244,7 @@ struct CanonicalLanguageID {
inline ErrorOr<NonnullOwnPtr<Core::Stream::BufferedFile>> open_file(StringView path, Core::Stream::OpenMode mode)
{
if (path.is_empty())
return Error::from_string_literal("Provided path is empty, please provide all command line options"sv);
return Error::from_string_literal("Provided path is empty, please provide all command line options");
auto file = TRY(Core::Stream::File::open(path, mode));
return Core::Stream::BufferedFile::create(move(file));
@ -273,8 +273,12 @@ inline ErrorOr<Core::DirIterator> path_to_dir_iterator(String path, StringView s
lexical_path = lexical_path.append(subpath);
Core::DirIterator iterator(lexical_path.string(), Core::DirIterator::SkipParentAndBaseDir);
if (iterator.has_error())
return Error::from_string_literal(iterator.error_string());
if (iterator.has_error()) {
// FIXME: Make Core::DirIterator return a StringView for its error
// string.
auto const* error_string_ptr = iterator.error_string();
return Error::from_string_view({ error_string_ptr, strlen(error_string_ptr) });
}
return iterator;
}
@ -282,8 +286,12 @@ inline ErrorOr<Core::DirIterator> path_to_dir_iterator(String path, StringView s
inline ErrorOr<String> next_path_from_dir_iterator(Core::DirIterator& iterator)
{
auto next_path = iterator.next_full_path();
if (iterator.has_error())
return Error::from_string_literal(iterator.error_string());
if (iterator.has_error()) {
// FIXME: Make Core::DirIterator return a StringView for its error
// string.
auto const* error_string_ptr = iterator.error_string();
return Error::from_string_view({ error_string_ptr, strlen(error_string_ptr) });
}
return next_path;
}