1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 13:37:10 +09:00
ladybird/Libraries/LibWeb/URLPattern/URLPattern.h
Shannon Booth 8a33c57c1e LibWeb/LibURL: Use an IgnoreCase enum for URLPatternOptions
This is to save a future name conflict that will appear between
the options IDL dictionary and the options struct that are both
present in the spec.

It is also a nicer interface for now given there is only a single
option at the moment.
2025-04-06 08:24:54 -04:00

62 lines
2.1 KiB
C++

/*
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibURL/Pattern/Init.h>
#include <LibURL/Pattern/Pattern.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::URLPattern {
using URLPatternInit = URL::Pattern::Init;
using URLPatternInput = URL::Pattern::Input;
using URLPatternResult = URL::Pattern::Result;
// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions
struct URLPatternOptions {
bool ignore_case { false };
};
// https://urlpattern.spec.whatwg.org/#urlpattern
class URLPattern : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URLPattern, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(URLPattern);
public:
static WebIDL::ExceptionOr<GC::Ref<URLPattern>> create(JS::Realm&, URLPatternInput const&, Optional<String> const& base_url, URLPatternOptions const& = {});
static WebIDL::ExceptionOr<GC::Ref<URLPattern>> construct_impl(JS::Realm&, URLPatternInput const&, String const& base_url, URLPatternOptions const& = {});
static WebIDL::ExceptionOr<GC::Ref<URLPattern>> construct_impl(JS::Realm&, URLPatternInput const&, URLPatternOptions const& = {});
WebIDL::ExceptionOr<bool> test(URLPatternInput const&, Optional<String> const& base_url) const;
WebIDL::ExceptionOr<Optional<URLPatternResult>> exec(URLPatternInput const&, Optional<String> const& base_url) const;
String const& protocol() const;
String const& username() const;
String const& password() const;
String const& hostname() const;
String const& port() const;
String const& pathname() const;
String const& search() const;
String const& hash() const;
bool has_reg_exp_groups() const;
virtual ~URLPattern() override;
protected:
virtual void initialize(JS::Realm&) override;
explicit URLPattern(JS::Realm&, URL::Pattern::Pattern);
private:
// https://urlpattern.spec.whatwg.org/#ref-for-url-pattern%E2%91%A0
// Each URLPattern has an associated URL pattern, a URL pattern.
URL::Pattern::Pattern m_url_pattern;
};
}