mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
bind more ada functions
also includes a fix for releasing memory if parsing failed
This commit is contained in:
39
vendor/ada/root.zig
vendored
39
vendor/ada/root.zig
vendored
@@ -19,7 +19,6 @@ pub const ParseError = error{Invalid};
|
|||||||
pub fn parse(input: []const u8) ParseError!URL {
|
pub fn parse(input: []const u8) ParseError!URL {
|
||||||
const url = c.ada_parse(input.ptr, input.len);
|
const url = c.ada_parse(input.ptr, input.len);
|
||||||
if (!c.ada_is_valid(url)) {
|
if (!c.ada_is_valid(url)) {
|
||||||
free(url);
|
|
||||||
return error.Invalid;
|
return error.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ pub fn parse(input: []const u8) ParseError!URL {
|
|||||||
pub fn parseWithBase(input: []const u8, base: []const u8) ParseError!URL {
|
pub fn parseWithBase(input: []const u8, base: []const u8) ParseError!URL {
|
||||||
const url = c.ada_parse_with_base(input.ptr, input.len, base.ptr, base.len);
|
const url = c.ada_parse_with_base(input.ptr, input.len, base.ptr, base.len);
|
||||||
if (!c.ada_is_valid(url)) {
|
if (!c.ada_is_valid(url)) {
|
||||||
free(url);
|
|
||||||
return error.Invalid;
|
return error.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +51,11 @@ pub inline fn isValid(url: URL) bool {
|
|||||||
return c.ada_is_valid(url);
|
return c.ada_is_valid(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new `URL` from given `URL`.
|
||||||
|
pub inline fn copy(url: URL) URL {
|
||||||
|
return c.ada_copy(url);
|
||||||
|
}
|
||||||
|
|
||||||
/// Can return an empty string.
|
/// Can return an empty string.
|
||||||
/// Contrary to other getters, returned slice is heap allocated.
|
/// Contrary to other getters, returned slice is heap allocated.
|
||||||
pub inline fn getOrigin(url: URL) []const u8 {
|
pub inline fn getOrigin(url: URL) []const u8 {
|
||||||
@@ -92,9 +95,18 @@ pub inline fn getHash(url: URL) []const u8 {
|
|||||||
return hash.data[0..hash.length];
|
return hash.data[0..hash.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an empty string if not provided.
|
pub inline fn getHashNullable(url: URL) String {
|
||||||
|
return c.ada_get_hash(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `data` is null if host not provided.
|
||||||
|
pub inline fn getHostNullable(url: URL) String {
|
||||||
|
return c.ada_get_host(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns an empty string if host not provided.
|
||||||
pub inline fn getHost(url: URL) []const u8 {
|
pub inline fn getHost(url: URL) []const u8 {
|
||||||
const host = c.ada_get_host(url);
|
const host = getHostNullable(url);
|
||||||
if (host.data == null) {
|
if (host.data == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -111,6 +123,10 @@ pub inline fn getHostname(url: URL) []const u8 {
|
|||||||
return hostname.data[0..hostname.length];
|
return hostname.data[0..hostname.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub inline fn getPathnameNullable(url: URL) String {
|
||||||
|
return c.ada_get_pathname(url);
|
||||||
|
}
|
||||||
|
|
||||||
pub inline fn getPathname(url: URL) []const u8 {
|
pub inline fn getPathname(url: URL) []const u8 {
|
||||||
const pathname = c.ada_get_pathname(url);
|
const pathname = c.ada_get_pathname(url);
|
||||||
return pathname.data[0..pathname.length];
|
return pathname.data[0..pathname.length];
|
||||||
@@ -168,3 +184,18 @@ pub inline fn setHash(url: URL, input: []const u8) void {
|
|||||||
pub inline fn clearSearch(url: URL) void {
|
pub inline fn clearSearch(url: URL) void {
|
||||||
return c.ada_clear_search(url);
|
return c.ada_clear_search(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const Scheme = struct {
|
||||||
|
pub const http: u8 = 0;
|
||||||
|
pub const not_special: u8 = 1;
|
||||||
|
pub const https: u8 = 2;
|
||||||
|
pub const ws: u8 = 3;
|
||||||
|
pub const ftp: u8 = 4;
|
||||||
|
pub const wss: u8 = 5;
|
||||||
|
pub const file: u8 = 6;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Returns one of the constants defined in `Scheme`.
|
||||||
|
pub inline fn getSchemeType(url: URL) u8 {
|
||||||
|
return c.ada_get_scheme_type(url);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user