Skip to content

Commit bfe78d1

Browse files
committed
bind more ada-url functions
1 parent 30d147e commit bfe78d1

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

vendor/ada/root.zig

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const c = @cImport({
77

88
/// Pointer type.
99
pub const URL = c.ada_url;
10+
pub const URLComponents = c.ada_url_components;
11+
pub const URLOmitted = c.ada_url_omitted;
1012
pub const String = c.ada_string;
1113
pub const OwnedString = c.ada_owned_string;
1214
/// Pointer type.
@@ -34,6 +36,10 @@ pub fn parseWithBase(input: []const u8, base: []const u8) ParseError!URL {
3436
return url;
3537
}
3638

39+
pub inline fn getComponents(url: URL) *const URLComponents {
40+
return c.ada_get_components(url);
41+
}
42+
3743
pub inline fn free(url: URL) void {
3844
return c.ada_free(url);
3945
}
@@ -42,6 +48,11 @@ pub inline fn freeOwnedString(owned: OwnedString) void {
4248
return c.ada_free_owned_string(owned);
4349
}
4450

51+
/// Returns true if given URL is valid (not NULL).
52+
pub inline fn isValid(url: URL) bool {
53+
return c.ada_is_valid(url);
54+
}
55+
4556
/// Can return an empty string.
4657
/// Contrary to other getters, returned slice is heap allocated.
4758
pub inline fn getOrigin(url: URL) []const u8 {
@@ -68,6 +79,10 @@ pub inline fn getPassword(url: URL) []const u8 {
6879
}
6980

7081
pub inline fn getPort(url: URL) []const u8 {
82+
if (!c.ada_has_port(url)) {
83+
return "";
84+
}
85+
7186
const port = c.ada_get_port(url);
7287
return port.data[0..port.length];
7388
}
@@ -77,12 +92,21 @@ pub inline fn getHash(url: URL) []const u8 {
7792
return hash.data[0..hash.length];
7893
}
7994

95+
/// Returns an empty string if not provided.
8096
pub inline fn getHost(url: URL) []const u8 {
8197
const host = c.ada_get_host(url);
98+
if (host.data == null) {
99+
return "";
100+
}
101+
82102
return host.data[0..host.length];
83103
}
84104

85105
pub inline fn getHostname(url: URL) []const u8 {
106+
if (!c.ada_has_hostname(url)) {
107+
return "";
108+
}
109+
86110
const hostname = c.ada_get_hostname(url);
87111
return hostname.data[0..hostname.length];
88112
}
@@ -92,12 +116,55 @@ pub inline fn getPathname(url: URL) []const u8 {
92116
return pathname.data[0..pathname.length];
93117
}
94118

95-
pub inline fn getSearch(url: URL) []const u8 {
96-
const search = c.ada_get_search(url);
97-
return search.data[0..search.length];
119+
pub inline fn getSearch(url: URL) String {
120+
return c.ada_get_search(url);
98121
}
99122

100123
pub inline fn getProtocol(url: URL) []const u8 {
101124
const protocol = c.ada_get_protocol(url);
102125
return protocol.data[0..protocol.length];
103126
}
127+
128+
pub inline fn setHref(url: URL, input: []const u8) bool {
129+
return c.ada_set_href(url, input.ptr, input.len);
130+
}
131+
132+
pub inline fn setHost(url: URL, input: []const u8) bool {
133+
return c.ada_set_host(url, input.ptr, input.len);
134+
}
135+
136+
pub inline fn setHostname(url: URL, input: []const u8) bool {
137+
return c.ada_set_hostname(url, input.ptr, input.len);
138+
}
139+
140+
pub inline fn setProtocol(url: URL, input: []const u8) bool {
141+
return c.ada_set_protocol(url, input.ptr, input.len);
142+
}
143+
144+
pub inline fn setUsername(url: URL, input: []const u8) bool {
145+
return c.ada_set_username(url, input.ptr, input.len);
146+
}
147+
148+
pub inline fn setPassword(url: URL, input: []const u8) bool {
149+
return c.ada_set_password(url, input.ptr, input.len);
150+
}
151+
152+
pub inline fn setPort(url: URL, input: []const u8) bool {
153+
return c.ada_set_port(url, input.ptr, input.len);
154+
}
155+
156+
pub inline fn setPathname(url: URL, input: []const u8) bool {
157+
return c.ada_set_pathname(url, input.ptr, input.len);
158+
}
159+
160+
pub inline fn setSearch(url: URL, input: []const u8) void {
161+
return c.ada_set_search(url, input.ptr, input.len);
162+
}
163+
164+
pub inline fn setHash(url: URL, input: []const u8) void {
165+
return c.ada_set_hash(url, input.ptr, input.len);
166+
}
167+
168+
pub inline fn clearSearch(url: URL) void {
169+
return c.ada_clear_search(url);
170+
}

0 commit comments

Comments
 (0)