mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
feat: bun patch (#11470)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: zackradisic <zackradisic@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
@@ -4037,6 +4037,20 @@ pub fn encodeBytesToHex(destination: []u8, source: []const u8) usize {
|
||||
return to_read * 2;
|
||||
}
|
||||
|
||||
/// Leave a single leading char
|
||||
/// ```zig
|
||||
/// trimSubsequentLeadingChars("foo\n\n\n\n", '\n') -> "foo\n"
|
||||
/// ```
|
||||
pub fn trimSubsequentLeadingChars(slice: []const u8, char: u8) []const u8 {
|
||||
if (slice.len == 0) return slice;
|
||||
var end = slice.len - 1;
|
||||
var endend = slice.len;
|
||||
while (end > 0 and slice[end] == char) : (end -= 1) {
|
||||
endend = end + 1;
|
||||
}
|
||||
return slice[0..endend];
|
||||
}
|
||||
|
||||
pub fn trimLeadingChar(slice: []const u8, char: u8) []const u8 {
|
||||
if (indexOfNotChar(slice, char)) |i| {
|
||||
return slice[i..];
|
||||
|
||||
Reference in New Issue
Block a user