mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:07:35 +00:00
AK: Add a new, spec-compliant URLParser
This adds a new URL parser, which aims to be compliant with the URL specification (https://url.spec.whatwg.org/). It also contains a rudimentary data URL parser.
This commit is contained in:
parent
8a938a3e25
commit
0d0ed4962f
5 changed files with 744 additions and 0 deletions
49
AK/URLParser.h
Normal file
49
AK/URLParser.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 {
|
||||
|
||||
class URLParser {
|
||||
public:
|
||||
enum class State {
|
||||
SchemeStart,
|
||||
Scheme,
|
||||
NoScheme,
|
||||
SpecialRelativeOrAuthority,
|
||||
PathOrAuthority,
|
||||
Relative,
|
||||
RelativeSlash,
|
||||
SpecialAuthoritySlashes,
|
||||
SpecialAuthorityIgnoreSlashes,
|
||||
Authority,
|
||||
Host,
|
||||
Hostname,
|
||||
Port,
|
||||
File,
|
||||
FileSlash,
|
||||
FileHost,
|
||||
PathStart,
|
||||
Path,
|
||||
CannotBeABaseUrlPath,
|
||||
Query,
|
||||
Fragment
|
||||
};
|
||||
|
||||
static URL parse(Badge<URL>, const StringView& input, const URL* base_url = nullptr);
|
||||
|
||||
private:
|
||||
static Optional<URL> parse_data_url(const StringView& raw_input);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::URLParser;
|
Loading…
Add table
Add a link
Reference in a new issue