aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 3a555d670..6599d8ba1 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -303,6 +303,19 @@ pub inline fn endsWithChar(self: string, char: u8) bool {
return self.len == 0 or self[self.len - 1] == char;
}
+pub fn withoutTrailingSlash(this: string) []const u8 {
+ var href = this;
+ while (href.len > 1 and href[href.len - 1] == '/') {
+ href = href[0 .. href.len - 1];
+ }
+
+ return href;
+}
+
+pub fn withoutLeadingSlash(this: string) []const u8 {
+ return std.mem.trimLeft(u8, this, "/");
+}
+
pub fn endsWithAny(self: string, str: string) bool {
const end = self[self.len - 1];
for (str) |char| {