commit 45231d7cf5986efd9397ed211c80887f9a690a1e
parent 138a84601a9f4dd7d8908346710885e15ef4456b
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 9 Feb 2023 23:23:30 +0100
net::uri: add dup
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/net/uri/uri.ha b/net/uri/uri.ha
@@ -1,4 +1,5 @@
use net::ip;
+use strings;
// Representation of a parsed URI.
export type uri = struct {
@@ -13,6 +14,26 @@ export type uri = struct {
fragment: str,
};
+// Duplicates a [[uri]].
+export fn dup(u: *uri) uri = {
+ return uri {
+ scheme = strings::dup(u.scheme),
+
+ host = match (u.host) {
+ case let host: str =>
+ yield strings::dup(host);
+ case let ip: ip::addr =>
+ yield strings::dup(ip::string(ip));
+ },
+ port = u.port,
+ userinfo = strings::dup(u.userinfo),
+
+ path = strings::dup(u.path),
+ query = strings::dup(u.query),
+ fragment = strings::dup(u.fragment),
+ };
+};
+
// Frees resources associated with a [[uri]].
export fn finish(u: *uri) void = {
free(u.scheme);