add URL.canParse static method

This commit is contained in:
Halil Durak
2025-10-23 13:30:39 +03:00
parent 1015fc09ee
commit 7808d12de2
2 changed files with 20 additions and 0 deletions

View File

@@ -132,6 +132,18 @@ pub const URL = struct {
return ada.clearHash(self.internal); return ada.clearHash(self.internal);
} }
/// Returns a boolean indicating whether or not an absolute URL,
/// or a relative URL combined with a base URL, are parsable and valid.
pub fn static_canParse(url: ConstructorArg, maybe_base: ?ConstructorArg, page: *Page) !bool {
const url_str = try url.toString(page);
if (maybe_base) |base| {
return ada.canParseWithBase(url_str, try base.toString(page));
}
return ada.canParse(url_str);
}
/// Alias to get_href. /// Alias to get_href.
pub fn _toString(self: *const URL, page: *Page) ![]const u8 { pub fn _toString(self: *const URL, page: *Page) ![]const u8 {
return self.get_href(page); return self.get_href(page);

8
vendor/ada/root.zig vendored
View File

@@ -33,6 +33,14 @@ pub fn parseWithBase(input: []const u8, base: []const u8) ParseError!URL {
return url; return url;
} }
pub inline fn canParse(input: []const u8) bool {
return c.ada_can_parse(input.ptr, input.len);
}
pub inline fn canParseWithBase(input: []const u8, base: []const u8) bool {
return c.ada_can_parse_with_base(input.ptr, input.len, base.ptr, base.len);
}
pub inline fn getComponents(url: URL) *const URLComponents { pub inline fn getComponents(url: URL) *const URLComponents {
return c.ada_get_components(url); return c.ada_get_components(url);
} }