aboutsummaryrefslogtreecommitdiff
path: root/url.ha
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--url.ha20
1 files changed, 20 insertions, 0 deletions
diff --git a/url.ha b/url.ha
new file mode 100644
index 0000000..1c511ba
--- /dev/null
+++ b/url.ha
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
+
+use strings;
+use net::uri;
+
+// The result, if not erroring out, must be freed with strings::freeall.
+fn segments_from_path(s: str) ([]str | nomem | uri::invalid) = {
+ let sp: []str = strings::split(s, "/")?;
+ for (let i = 1z; i < len(sp); i += 1) {
+ match (uri::percent_decode(sp[i])) {
+ case let s: str =>
+ sp[i - 1] = s;
+ case uri::invalid =>
+ strings::freeall(sp[.. i - 1]);
+ return uri::invalid;
+ };
+ };
+ return sp[.. len(sp) - 1];
+};