diff options
author | 2021-04-25 18:47:09 -0700 | |
---|---|---|
committer | 2021-04-25 18:47:09 -0700 | |
commit | 99918c35ec1ddc11650e620a61361523099c96f5 (patch) | |
tree | 871b8ab2a0c746003e3c9e128a32f1513e3e7394 /src/string_immutable.zig | |
parent | c0b7f71b9ace0bfd91fb5e0364f104b5093e6c37 (diff) | |
download | bun-99918c35ec1ddc11650e620a61361523099c96f5.tar.gz bun-99918c35ec1ddc11650e620a61361523099c96f5.tar.zst bun-99918c35ec1ddc11650e620a61361523099c96f5.zip |
it prints true and false
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index f9d485df6..abfeec072 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -25,6 +25,52 @@ pub fn indexOf(self: string, str: u8) ?usize { return std.mem.indexOf(u8, self, str); } +pub fn startsWith(self: string, str: string) bool { + if (str.len > self.len) { + return false; + } + + var i: usize = 0; + while (i < str.len) { + if (str[i] != self[i]) { + return false; + } + i += 1; + } + + return true; +} + +pub fn endsWithAny(self: string, str: string) bool { + const end = self[self.len - 1]; + for (str) |char| { + if (char == end) { + return true; + } + } + + return false; +} + +pub fn lastNonwhitespace(self: string, str: string) bool { + +} + +pub fn endsWithAnyComptime(self: string, comptime str: string) bool { + if (str.len < 10) { + const last = self[self.len - 1]; + inline while (str) |char| { + if (char == last) { + return true; + } + } + + return false; + } else { + return endsWithAny(self, str); + } +} + pub fn eql(self: string, other: anytype) bool { return std.mem.eql(u8, self, other); } |