serenity/AK/URLParser.h
Idan Horowitz 55b67ba7a7 AK: Accept optional url and state override parameters in URLParser
These are required in the specification and used by the web's URL
built-in, this commit also removes the Badge<AK::URL> from URLParser
to allow other classes that need to call the parser directly like the
web's URL built-in to do so.
2021-09-14 00:14:45 +02:00

69 lines
1.7 KiB
C++

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