mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
97425c7dfb
This patch adds a state_name method to URLParser to convert a state to a string. With this, the debugging statements now display the state names. Furthermore, this fixes a bug where non-ASCII code points were formatted as characters, which fails an assertion in the formatting system.
68 lines
1.7 KiB
C++
68 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(Badge<URL>, StringView const& input, URL const* base_url = nullptr);
|
|
|
|
private:
|
|
static Optional<URL> parse_data_url(StringView const& raw_input);
|
|
};
|
|
|
|
#undef ENUMERATE_STATES
|
|
|
|
}
|
|
|
|
using AK::URLParser;
|