std: add .startsWith and .endsWith to std.ArrayList
This commit is contained in:
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ pub const Buffer = struct {
|
||||
|
||||
pub fn startsWith(self: Buffer, m: []const u8) bool {
|
||||
if (self.len() < m.len) return false;
|
||||
return mem.eql(u8, self.list.items[0..m.len], m);
|
||||
return self.list.startsWith(m);
|
||||
}
|
||||
|
||||
pub fn endsWith(self: Buffer, m: []const u8) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user