1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 09:20:46 +00:00
serenity/AK/URLParser.h
Andreas Kling ae3ffdd521 AK: Make it possible to not using AK classes into the global namespace
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by
default, but can be overridden by build flags.

This is a step towards integrating Jakt and AK types.
2022-11-26 15:51:34 +01:00

71 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 input, URL const* base_url = nullptr, Optional<URL> url = {}, Optional<State> state_override = {});
private:
static Optional<URL> parse_data_url(StringView raw_input);
};
#undef ENUMERATE_STATES
}
#if USING_AK_GLOBALLY
using AK::URLParser;
#endif