2021-05-25 20:13:15 +00:00
|
|
|
/*
|
|
|
|
* 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 {
|
|
|
|
|
2021-06-03 10:40:04 +00:00
|
|
|
#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)
|
|
|
|
|
2021-05-25 20:13:15 +00:00
|
|
|
class URLParser {
|
|
|
|
public:
|
|
|
|
enum class State {
|
2021-06-03 10:40:04 +00:00
|
|
|
#define STATE(state) state,
|
|
|
|
ENUMERATE_STATES
|
|
|
|
#undef STATE
|
2021-05-25 20:13:15 +00:00
|
|
|
};
|
|
|
|
|
2021-06-03 10:40:04 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-06-03 10:03:56 +00:00
|
|
|
static URL parse(Badge<URL>, StringView const& input, URL const* base_url = nullptr);
|
2021-05-25 20:13:15 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-03 10:03:56 +00:00
|
|
|
static Optional<URL> parse_data_url(StringView const& raw_input);
|
2021-05-25 20:13:15 +00:00
|
|
|
};
|
|
|
|
|
2021-06-03 10:40:04 +00:00
|
|
|
#undef ENUMERATE_STATES
|
|
|
|
|
2021-05-25 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using AK::URLParser;
|