/* * Copyright (c) 2021, Max Wipfli * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include 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 { #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(StringView input, Optional const& base_url = {}, Optional url = {}, Optional state_override = {}); private: static Optional parse_data_url(StringView raw_input); }; #undef ENUMERATE_STATES } #if USING_AK_GLOBALLY using AK::URLParser; #endif