diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index daedbc50c9a..880ef04a50e 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -228,10 +228,12 @@ URL URLParser::parse(Badge, StringView const& raw_input, URL const* base_ur code_point = *iterator; if constexpr (URL_PARSER_DEBUG) { - if (code_point) - dbgln("URLParser::parse: State {:2d} with code point '{:c}' (U+{:04X}).", (int)state, code_point, code_point); + if (!code_point) + dbgln("URLParser::parse: {} state with EOF.", state_name(state)); + else if (is_ascii_printable(code_point)) + dbgln("URLParser::parse: {} state with code point U+{:04X} ({:c}).", state_name(state), code_point, code_point); else - dbgln("URLParser::parse: State {:2d} with code point EOF (U+0000).", (int)state); + dbgln("URLParser::parse: {} state with code point U+{:04X}.", state_name(state), code_point); } switch (state) { diff --git a/AK/URLParser.h b/AK/URLParser.h index ea403751d0f..d58451daf96 100644 --- a/AK/URLParser.h +++ b/AK/URLParser.h @@ -12,38 +12,57 @@ namespace AK { +#define ENUMERATE_STATES \ + STATE(SchemeStart) \ + STATE(Scheme) \ + STATE(NoScheme) \ + STATE(SpecialRelativeOrAuthority) \ + STATE(PathOrAuthority) \ + STATE(Relative) \ + STATE(RelativeSlash) \ + STATE(SpecialAuthoritySlashes) \ + STATE(SpecialAuthorityIgnoreSlashes) \ + STATE(Authority) \ + STATE(Host) \ + STATE(Hostname) \ + STATE(Port) \ + STATE(File) \ + STATE(FileSlash) \ + STATE(FileHost) \ + STATE(PathStart) \ + STATE(Path) \ + STATE(CannotBeABaseUrlPath) \ + STATE(Query) \ + STATE(Fragment) + class URLParser { public: enum class State { - SchemeStart, - Scheme, - NoScheme, - SpecialRelativeOrAuthority, - PathOrAuthority, - Relative, - RelativeSlash, - SpecialAuthoritySlashes, - SpecialAuthorityIgnoreSlashes, - Authority, - Host, - Hostname, - Port, - File, - FileSlash, - FileHost, - PathStart, - Path, - CannotBeABaseUrlPath, - Query, - Fragment +#define STATE(state) state, + ENUMERATE_STATES +#undef STATE }; + static char const* state_name(State const& state) + { + switch (state) { +#define STATE(state) \ + case State::state: \ + return #state; + ENUMERATE_STATES +#undef STATE + } + VERIFY_NOT_REACHED(); + } + static URL parse(Badge, StringView const& input, URL const* base_url = nullptr); private: static Optional parse_data_url(StringView const& raw_input); }; +#undef ENUMERATE_STATES + } using AK::URLParser;