std: add .startsWith and .endsWith to std.ArrayList

This commit is contained in:
daurnimator
2020-02-07 14:17:40 +11:00
committed by Andrew Kelley
parent fa46bcb368
commit 119ac13eda
2 changed files with 12 additions and 1 deletions

View File

@@ -248,6 +248,17 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
if (self.len == 0) return null;
return self.pop();
}
pub fn startsWith(self: Self, m: []const T) bool {
if (self.len < m.len) return false;
return mem.eql(T, self.items[0..m.len], m);
}
pub fn endsWith(self: Self, m: []const T) bool {
if (self.len < m.len) return false;
const start = self.len - m.len;
return mem.eql(T, self.items[start..self.len], m);
}
};
}