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