| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn trimSuffix(in: string, suffix: string) string { |
| 6 | if (std.mem.endsWith(u8, in, suffix)) { |
| 7 | return in[0 .. in.len - suffix.len]; |
| 8 | } |
| 9 | return in; |
| 10 | } |
| 11 | |
| 12 | test { |
| 13 | try std.testing.expect(std.mem.eql(u8, trimSuffix("abaabbaaba", "c"), "abaabbaaba")); |
| 14 | } |
| 15 | test { |
| 16 | try std.testing.expect(std.mem.eql(u8, trimSuffix("abaabbaaba", "aba"), "abaabba")); |
| 17 | } |