aboutsummaryrefslogtreecommitdiff
path: root/mirai.old/fs/afs/location.zig
diff options
context:
space:
mode:
Diffstat (limited to 'mirai.old/fs/afs/location.zig')
-rw-r--r--mirai.old/fs/afs/location.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/mirai.old/fs/afs/location.zig b/mirai.old/fs/afs/location.zig
new file mode 100644
index 0000000..c5ede65
--- /dev/null
+++ b/mirai.old/fs/afs/location.zig
@@ -0,0 +1,30 @@
+//! AFS location utilities
+
+pub fn parent(location: []const u8) []const u8 {
+ var i: usize = location.len;
+ while (i > 0) : (i -= 1) {
+ if (location[i - 1] == '/') {
+ if (i == 1) return "/";
+ return location[0 .. i - 1];
+ }
+ }
+ return "/";
+}
+
+pub fn identity(location: []const u8) []const u8 {
+ var i: usize = location.len;
+ while (i > 0) : (i -= 1) {
+ if (location[i - 1] == '/') {
+ return location[i..];
+ }
+ }
+ return location;
+}
+
+pub fn is_absolute(location: []const u8) bool {
+ return location.len > 0 and location[0] == '/';
+}
+
+pub fn skip_root(location: []const u8) usize {
+ return if (is_absolute(location)) 1 else 0;
+}