std: add .startsWith and .endsWith to std.ArrayList
This commit is contained in:
committed by
Andrew Kelley
parent
fa46bcb368
commit
119ac13eda
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user