Skip to content

Commit

Permalink
Everywhere: Convert from_string_view -> from_string_literal where static
Browse files Browse the repository at this point in the history
(cherry picked from commit 229b64a4b723a391c21f247d72d78cd575ace6ff;
minorly amended to fix conflict in image.cpp due to serenity in the
meantime adding webp writing support, and due to changes in Android and
Vulkan-related files that serenity doesn't have)
  • Loading branch information
asutoshvariar authored and nico committed Nov 15, 2024
1 parent f63a156 commit 50cc1b5
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 76 deletions.
14 changes: 7 additions & 7 deletions Ladybird/Qt/AutoComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ AutoComplete::AutoComplete(QWidget* parent)
ErrorOr<Vector<String>> AutoComplete::parse_google_autocomplete(Vector<JsonValue> const& json)
{
if (json.size() != 5)
return Error::from_string_view("Invalid JSON, expected 5 elements in array"sv);
return Error::from_string_literal("Invalid JSON, expected 5 elements in array");

if (!json[0].is_string())
return Error::from_string_view("Invalid JSON, expected first element to be a string"sv);
return Error::from_string_literal("Invalid JSON, expected first element to be a string");
auto query = TRY(String::from_byte_string(json[0].as_string()));

if (!json[1].is_array())
return Error::from_string_view("Invalid JSON, expected second element to be an array"sv);
return Error::from_string_literal("Invalid JSON, expected second element to be an array");
auto suggestions_array = json[1].as_array().values();

if (query != m_query)
return Error::from_string_view("Invalid JSON, query does not match"sv);
return Error::from_string_literal("Invalid JSON, query does not match");

Vector<String> results;
results.ensure_capacity(suggestions_array.size());
Expand Down Expand Up @@ -86,13 +86,13 @@ ErrorOr<Vector<String>> AutoComplete::parse_yahoo_autocomplete(JsonObject const&
auto suggestions_object = json.get("r"sv)->as_array().values();

if (query != m_query)
return Error::from_string_view("Invalid JSON, query does not match"sv);
return Error::from_string_literal("Invalid JSON, query does not match");

Vector<String> results;
results.ensure_capacity(suggestions_object.size());
for (auto& suggestion_object : suggestions_object) {
if (!suggestion_object.is_object())
return Error::from_string_view("Invalid JSON, expected value to be an object"sv);
return Error::from_string_literal("Invalid JSON, expected value to be an object");
auto suggestion = suggestion_object.as_object();

if (!suggestion.get("k"sv).has_value() || !suggestion.get("k"sv)->is_string())
Expand Down Expand Up @@ -121,7 +121,7 @@ ErrorOr<void> AutoComplete::got_network_response(QNetworkReply* reply)
} else if (engine_name == "Yahoo")
results = TRY(parse_yahoo_autocomplete(json.as_object()));
else {
return Error::from_string_view("Invalid engine name"sv);
return Error::from_string_literal("Invalid engine name");
}

constexpr size_t MAX_AUTOCOMPLETE_RESULTS = 6;
Expand Down
2 changes: 1 addition & 1 deletion Ladybird/RequestServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
return Error::from_string_literal("Don't know how to load certs!");
return cert_path;
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/AK/TestJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ TEST_CASE(fallible_json_object_for_each)
}));

auto result1 = object.try_for_each_member([](auto const&, auto const&) -> ErrorOr<void> {
return Error::from_string_view("nanananana"sv);
return Error::from_string_literal("nanananana");
});
EXPECT(result1.is_error());
EXPECT_EQ(result1.error().string_literal(), "nanananana"sv);
Expand Down Expand Up @@ -402,7 +402,7 @@ TEST_CASE(fallible_json_array_for_each)
}));

auto result1 = array.try_for_each([](auto const&) -> ErrorOr<void> {
return Error::from_string_view("nanananana"sv);
return Error::from_string_literal("nanananana");
});
EXPECT(result1.is_error());
EXPECT_EQ(result1.error().string_literal(), "nanananana"sv);
Expand Down
24 changes: 12 additions & 12 deletions Userland/Libraries/LibAudio/FlacWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FlacWriter::~FlacWriter()
ErrorOr<void> FlacWriter::finalize()
{
if (m_state == WriteState::FullyFinalized)
return Error::from_string_view("File is already finalized"sv);
return Error::from_string_literal("File is already finalized");

if (m_state == WriteState::HeaderUnwritten)
TRY(finalize_header_format());
Expand Down Expand Up @@ -74,7 +74,7 @@ ErrorOr<void> FlacWriter::finalize()
ErrorOr<void> FlacWriter::finalize_header_format()
{
if (m_state != WriteState::HeaderUnwritten)
return Error::from_string_view("Header format is already finalized"sv);
return Error::from_string_literal("Header format is already finalized");
TRY(write_header());
m_state = WriteState::FormatFinalized;
return {};
Expand All @@ -83,9 +83,9 @@ ErrorOr<void> FlacWriter::finalize_header_format()
ErrorOr<void> FlacWriter::set_num_channels(u8 num_channels)
{
if (m_state != WriteState::HeaderUnwritten)
return Error::from_string_view("Header format is already finalized"sv);
return Error::from_string_literal("Header format is already finalized");
if (num_channels > 8)
return Error::from_string_view("FLAC doesn't support more than 8 channels"sv);
return Error::from_string_literal("FLAC doesn't support more than 8 channels");

m_num_channels = num_channels;
return {};
Expand All @@ -94,7 +94,7 @@ ErrorOr<void> FlacWriter::set_num_channels(u8 num_channels)
ErrorOr<void> FlacWriter::set_sample_rate(u32 sample_rate)
{
if (m_state != WriteState::HeaderUnwritten)
return Error::from_string_view("Header format is already finalized"sv);
return Error::from_string_literal("Header format is already finalized");

m_sample_rate = sample_rate;
return {};
Expand All @@ -103,9 +103,9 @@ ErrorOr<void> FlacWriter::set_sample_rate(u32 sample_rate)
ErrorOr<void> FlacWriter::set_bits_per_sample(u16 bits_per_sample)
{
if (m_state != WriteState::HeaderUnwritten)
return Error::from_string_view("Header format is already finalized"sv);
return Error::from_string_literal("Header format is already finalized");
if (bits_per_sample < 8 || bits_per_sample > 32)
return Error::from_string_view("FLAC only supports bits per sample between 8 and 32"sv);
return Error::from_string_literal("FLAC only supports bits per sample between 8 and 32");

m_bits_per_sample = bits_per_sample;
return {};
Expand Down Expand Up @@ -246,7 +246,7 @@ ErrorOr<void> FlacWriter::write_header()
ErrorOr<void> FlacWriter::add_metadata_block(FlacRawMetadataBlock block, Optional<size_t> insertion_index)
{
if (m_state != WriteState::HeaderUnwritten)
return Error::from_string_view("Metadata blocks can only be added before the header is finalized"sv);
return Error::from_string_literal("Metadata blocks can only be added before the header is finalized");

if (insertion_index.has_value())
TRY(m_cached_metadata_blocks.try_insert(insertion_index.value(), move(block)));
Expand All @@ -260,11 +260,11 @@ ErrorOr<void> FlacWriter::write_metadata_block(FlacRawMetadataBlock& block)
{
if (m_state == WriteState::FormatFinalized) {
if (!m_last_padding.has_value())
return Error::from_string_view("No (more) padding available to write block into"sv);
return Error::from_string_literal("No (more) padding available to write block into");

auto const last_padding = m_last_padding.release_value();
if (block.length > last_padding.size)
return Error::from_string_view("Late metadata block doesn't fit in available padding"sv);
return Error::from_string_literal("Late metadata block doesn't fit in available padding");

auto const current_position = TRY(m_stream->tell());
ScopeGuard guard = [&] { (void)m_stream->seek(current_position, SeekMode::SetPosition); };
Expand Down Expand Up @@ -294,7 +294,7 @@ ErrorOr<void> FlacWriter::write_metadata_block(FlacRawMetadataBlock& block)
};
TRY(m_stream->write_value(new_padding_block));
} else if (new_size != 0) {
return Error::from_string_view("Remaining padding is not divisible by 4, there will be some stray zero bytes!"sv);
return Error::from_string_literal("Remaining padding is not divisible by 4, there will be some stray zero bytes!");
}

return {};
Expand Down Expand Up @@ -482,7 +482,7 @@ ErrorOr<void> FlacFrameHeader::write_to_stream(Stream& stream) const
ErrorOr<void> FlacWriter::write_samples(ReadonlySpan<Sample> samples)
{
if (m_state == WriteState::FullyFinalized)
return Error::from_string_view("File is already finalized"sv);
return Error::from_string_literal("File is already finalized");

auto remaining_samples = samples;
while (remaining_samples.size() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibAudio/MultiChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template<ArrayLike<i64> ChannelType, ArrayLike<ChannelType> InputType>
ErrorOr<FixedArray<Sample>> downmix_surround_to_stereo(InputType const& input, float sample_scale_factor)
{
if (input.size() == 0)
return Error::from_string_view("Cannot resample from 0 channels"sv);
return Error::from_string_literal("Cannot resample from 0 channels");

auto channel_count = input.size();
auto sample_count = input[0].size();
Expand Down Expand Up @@ -94,7 +94,7 @@ ErrorOr<FixedArray<Sample>> downmix_surround_to_stereo(InputType const& input, f
}
break;
default:
return Error::from_string_view("Invalid number of channels greater than 8"sv);
return Error::from_string_literal("Invalid number of channels greater than 8");
}

return output;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibAudio/VorbisComment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static ErrorOr<void> read_vorbis_field(Metadata& metadata_to_write_into, String
auto field_name_and_contents = TRY(unparsed_user_comment.split_limit('=', 2));

if (field_name_and_contents.size() != 2)
return Error::from_string_view("User comment does not contain '='"sv);
return Error::from_string_literal("User comment does not contain '='");
auto contents = field_name_and_contents.take_last();
auto field_name = TRY(field_name_and_contents.take_first().to_uppercase());

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ ErrorOr<bool> Process::is_being_debugged()
# endif
#endif
// FIXME: Implement this for more platforms.
return Error::from_string_view("Platform does not support checking for debugger"sv);
return Error::from_string_literal("Platform does not support checking for debugger");
}

// Forces the process to sleep until a debugger is attached, then breaks.
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/ResourceImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ErrorOr<NonnullRefPtr<Resource>> ResourceImplementation::load_from_uri(StringVie
}

dbgln("ResourceImplementation: Unknown scheme for {}", uri);
return Error::from_string_view("Invalid scheme"sv);
return Error::from_string_literal("Invalid scheme");
}

Vector<String> ResourceImplementation::child_names(Resource const& resource)
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibCore/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,16 +1876,16 @@ ErrorOr<ByteString> current_executable_path()
for (int32 cookie { 0 }; get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK && info.type != B_APP_IMAGE;)
;
if (info.type != B_APP_IMAGE)
return Error::from_string_view("current_executable_path() failed"sv);
return Error::from_string_literal("current_executable_path() failed");
if (sizeof(info.name) > sizeof(path))
return Error::from_errno(ENAMETOOLONG);
strlcpy(path, info.name, sizeof(path) - 1);
#elif defined(AK_OS_EMSCRIPTEN)
return Error::from_string_view("current_executable_path() unknown on this platform"sv);
return Error::from_string_literal("current_executable_path() unknown on this platform");
#else
# warning "Not sure how to get current_executable_path on this platform!"
// GetModuleFileName on Windows, unsure about OpenBSD.
return Error::from_string_view("current_executable_path unknown"sv);
return Error::from_string_literal("current_executable_path unknown");
#endif
path[sizeof(path) - 1] = '\0';
return ByteString { path, strlen(path) };
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibCrypto/ASN1/DER.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class Decoder {
ErrorOr<void> rewrite_tag(Kind kind)
{
if (m_stack.is_empty())
return Error::from_string_view("Nothing on stack to rewrite"sv);
return Error::from_string_literal("Nothing on stack to rewrite");

if (eof())
return Error::from_string_view("Stream is empty"sv);
return Error::from_string_literal("Stream is empty");

if (m_current_tag.has_value()) {
m_current_tag->kind = kind;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCrypto/Hash/MGF.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MGF {
// 1. If length > 2^32(hLen), output "mask too long" and stop.
if constexpr (sizeof(size_t) > 32) {
if (length > (h_len << 32))
return Error::from_string_view("mask too long"sv);
return Error::from_string_literal("mask too long");
}

// 2. Let T be the empty octet string.
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCrypto/Hash/PBKDF2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PBKDF2 {

// 1. If dkLen > (2^32 - 1) * hLen, output "derived key too long" and stop.
if (key_length_bytes > (AK::pow(2.0, 32.0) - 1) * h_len)
return Error::from_string_view("derived key too long"sv);
return Error::from_string_literal("derived key too long");

// 2 . Let l be the number of hLen-octet blocks in the derived key rounding up,
// and let r be the number of octets in the last block
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCrypto/Padding/OAEP.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OAEP {
auto h_len = HashFunction::digest_size();
auto max_message_size = length - (2 * h_len) - 1;
if (message.size() > max_message_size)
return Error::from_string_view("message too long"sv);
return Error::from_string_literal("message too long");

// 3. Generate an octet string PS consisting of emLen-||M||-2hLen-1 zero octets. The length of PS may be 0.
auto padding_size = length - message.size() - (2 * h_len) - 1;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibTLS/Certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static ErrorOr<SupportedGroup> oid_to_curve(Vector<int> curve)
else if (curve == curve_prime256)
return SupportedGroup::SECP256R1;

return Error::from_string_view("Unknown curve oid"sv);
return Error::from_string_literal("Unknown curve oid");
}

static ErrorOr<Crypto::UnsignedBigInteger> parse_certificate_version(Crypto::ASN1::Decoder& decoder, Vector<StringView> current_scope)
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/ARIA/RoleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ ErrorOr<void> RoleType::serialize_as_json(JsonObjectSerializer<StringBuilder>& o
ErrorOr<NonnullOwnPtr<RoleType>> RoleType::build_role_object(Role role, bool focusable, AriaData const& data)
{
if (is_abstract_role(role))
return Error::from_string_view("Cannot construct a role object for an abstract role."sv);
return Error::from_string_literal("Cannot construct a role object for an abstract role.");

switch (role) {
case Role::alert:
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ WebIDL::ExceptionOr<Variant<JS::NonnullGCPtr<CryptoKey>, JS::NonnullGCPtr<Crypto
// NOTE: Spec jumps to 6 here for some reason
// 6. If performing the key generation operation results in an error, then throw an OperationError.
auto maybe_private_key_data = curve.visit(
[](Empty const&) -> ErrorOr<ByteBuffer> { return Error::from_string_view("noop error"sv); },
[](Empty const&) -> ErrorOr<ByteBuffer> { return Error::from_string_literal("noop error"); },
[](auto instance) { return instance.generate_private_key(); });

if (maybe_private_key_data.is_error())
Expand All @@ -1115,7 +1115,7 @@ WebIDL::ExceptionOr<Variant<JS::NonnullGCPtr<CryptoKey>, JS::NonnullGCPtr<Crypto
auto private_key_data = maybe_private_key_data.release_value();

auto maybe_public_key_data = curve.visit(
[](Empty const&) -> ErrorOr<ByteBuffer> { return Error::from_string_view("noop error"sv); },
[](Empty const&) -> ErrorOr<ByteBuffer> { return Error::from_string_literal("noop error"); },
[&](auto instance) { return instance.generate_public_key(private_key_data); });

if (maybe_public_key_data.is_error())
Expand Down Expand Up @@ -1290,7 +1290,7 @@ WebIDL::ExceptionOr<JS::Value> ECDSA::verify(AlgorithmParams const& params, JS::
auto encoded_signature = encoder.finish();

auto maybe_result = curve.visit(
[](Empty const&) -> ErrorOr<bool> { return Error::from_string_view("Failed to create valid crypto instance"sv); },
[](Empty const&) -> ErrorOr<bool> { return Error::from_string_literal("Failed to create valid crypto instance"); },
[&](auto instance) { return instance.verify(M, Q, encoded_signature); });

if (maybe_result.is_error()) {
Expand Down Expand Up @@ -1517,7 +1517,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> PBKDF2::derive_bits(Algor
// the contents of the salt attribute of normalizedAlgorithm as the salt, S,
// the value of the iterations attribute of normalizedAlgorithm as the iteration count, c,
// and length divided by 8 as the intended key length, dkLen.
ErrorOr<ByteBuffer> result = Error::from_string_view("noop error"sv);
ErrorOr<ByteBuffer> result = Error::from_string_literal("noop error");

auto password = key->handle().get<ByteBuffer>();

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ ErrorOr<void> Element::scroll_into_view(Optional<Variant<bool, ScrollIntoViewOpt
// 6. If the element does not have any associated box, or is not available to user-agent features, then return.
document().update_layout();
if (!layout_node())
return Error::from_string_view("Element has no associated box"sv);
return Error::from_string_literal("Element has no associated box");

// 7. Scroll the element into view with behavior, block, and inline.
TRY(scroll_an_element_into_view(*this, behavior, block, inline_));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ErrorOr<Optional<URL::URL>> Response::location_url(Optional<String> const& reque
// 3. If location is a header value, then set location to the result of parsing location with response’s URL.
auto location = DOMURL::parse(location_values.first(), url().copy());
if (!location.is_valid())
return Error::from_string_view("Invalid 'Location' header URL"sv);
return Error::from_string_literal("Invalid 'Location' header URL");

// 4. If location is a URL whose fragment is null, then set location’s fragment to requestFragment.
if (!location.fragment().has_value())
Expand Down
Loading

0 comments on commit 50cc1b5

Please sign in to comment.