diff options
author | 2021-05-12 01:46:58 -0700 | |
---|---|---|
committer | 2021-05-12 01:46:58 -0700 | |
commit | f8131f42bcd039964586cbf3bd019dc9a449c438 (patch) | |
tree | 04af9a81309920ba04fd2e18d9f7fda3d615115b /src/string_immutable.zig | |
parent | 175bbdd3c3ef13c3446fc5712e9dfcf96d387f0a (diff) | |
download | bun-f8131f42bcd039964586cbf3bd019dc9a449c438.tar.gz bun-f8131f42bcd039964586cbf3bd019dc9a449c438.tar.zst bun-f8131f42bcd039964586cbf3bd019dc9a449c438.zip |
okay
Former-commit-id: 2c20d88e8d0cf66b32daceb942ba9bf8514f5705
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index bac82f9f2..55d94917b 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -45,6 +45,21 @@ pub fn startsWith(self: string, str: string) bool { return true; } +pub fn endsWith(self: string, str: string) bool { + if (str.len > self.len) { + return false; + } + + var i: usize = str.len - 1; + while (i > 0) : (i -= 1) { + if (str[i] != self[i]) { + return false; + } + } + + return true; +} + pub fn endsWithAny(self: string, str: string) bool { const end = self[self.len - 1]; for (str) |char| { |