mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:27:44 +00:00
AK: Remove ByteString from GenericLexer
A bunch of users used consume_specific with a constant ByteString literal, which can be replaced by an allocation-free StringView literal. The generic consume_while overload gains a requires clause so that consume_specific("abc") causes a more understandable and actionable error.
This commit is contained in:
parent
7c88ab2836
commit
eada4f2ee8
16 changed files with 89 additions and 86 deletions
|
@ -125,10 +125,10 @@ StringView FormatParser::consume_literal()
|
|||
auto const begin = tell();
|
||||
|
||||
while (!is_eof()) {
|
||||
if (consume_specific("{{"))
|
||||
if (consume_specific("{{"sv))
|
||||
continue;
|
||||
|
||||
if (consume_specific("}}"))
|
||||
if (consume_specific("}}"sv))
|
||||
continue;
|
||||
|
||||
if (next_is(is_any_of("{}"sv)))
|
||||
|
@ -858,7 +858,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars
|
|||
m_mode = Mode::Hexfloat;
|
||||
else if (parser.consume_specific('A'))
|
||||
m_mode = Mode::HexfloatUppercase;
|
||||
else if (parser.consume_specific("hex-dump"))
|
||||
else if (parser.consume_specific("hex-dump"sv))
|
||||
m_mode = Mode::HexDump;
|
||||
|
||||
if (!parser.is_eof())
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Result.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -92,9 +93,11 @@ public:
|
|||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
bool consume_specific(ByteString const& next)
|
||||
bool consume_specific(ByteString next) = delete;
|
||||
|
||||
bool consume_specific(String const& next)
|
||||
{
|
||||
return consume_specific(StringView { next });
|
||||
return consume_specific(next.bytes_as_string_view());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -298,21 +298,21 @@ ErrorOr<JsonValue> JsonParser::parse_number()
|
|||
|
||||
ErrorOr<JsonValue> JsonParser::parse_true()
|
||||
{
|
||||
if (!consume_specific("true"))
|
||||
if (!consume_specific("true"sv))
|
||||
return Error::from_string_literal("JsonParser: Expected 'true'");
|
||||
return JsonValue(true);
|
||||
}
|
||||
|
||||
ErrorOr<JsonValue> JsonParser::parse_false()
|
||||
{
|
||||
if (!consume_specific("false"))
|
||||
if (!consume_specific("false"sv))
|
||||
return Error::from_string_literal("JsonParser: Expected 'false'");
|
||||
return JsonValue(false);
|
||||
}
|
||||
|
||||
ErrorOr<JsonValue> JsonParser::parse_null()
|
||||
{
|
||||
if (!consume_specific("null"))
|
||||
if (!consume_specific("null"sv))
|
||||
return Error::from_string_literal("JsonParser: Expected 'null'");
|
||||
return JsonValue {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue