mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
feat(ENG-21324): Implement hosted_git_info.zig (#24138)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -414,6 +414,12 @@ pub fn indexOfSigned(self: string, str: string) i32 {
|
||||
return @as(i32, @intCast(i));
|
||||
}
|
||||
|
||||
/// Returns last index of `char` before a character `before`.
|
||||
pub fn lastIndexBeforeChar(in: []const u8, char: u8, before: u8) ?usize {
|
||||
const before_pos = indexOfChar(in, before) orelse in.len;
|
||||
return lastIndexOfChar(in[0..before_pos], char);
|
||||
}
|
||||
|
||||
pub fn lastIndexOfChar(self: []const u8, char: u8) callconv(bun.callconv_inline) ?usize {
|
||||
if (comptime Environment.isLinux) {
|
||||
if (@inComptime()) {
|
||||
@@ -1132,6 +1138,15 @@ pub fn index(self: string, str: string) i32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a substring starting at `start` up to the end of the string.
|
||||
/// If `start` is greater than the string's length, returns an empty string.
|
||||
pub fn substring(self: anytype, start: ?usize, stop: ?usize) @TypeOf(self) {
|
||||
const sta = start orelse 0;
|
||||
const sto = stop orelse self.len;
|
||||
|
||||
return self[@min(sta, self.len)..@min(sto, self.len)];
|
||||
}
|
||||
|
||||
pub const ascii_vector_size = if (Environment.isWasm) 8 else 16;
|
||||
pub const ascii_u16_vector_size = if (Environment.isWasm) 4 else 8;
|
||||
pub const AsciiVectorInt = std.meta.Int(.unsigned, ascii_vector_size);
|
||||
@@ -1553,6 +1568,13 @@ pub fn trimPrefixComptime(comptime T: type, buffer: []const T, comptime prefix:
|
||||
buffer;
|
||||
}
|
||||
|
||||
pub fn trimSuffixComptime(buffer: []const u8, comptime suffix: anytype) []const u8 {
|
||||
return if (hasSuffixComptime(buffer, suffix))
|
||||
buffer[0 .. buffer.len - suffix.len]
|
||||
else
|
||||
buffer;
|
||||
}
|
||||
|
||||
/// Get the line number and the byte offsets of `line_range_count` above the desired line number
|
||||
/// The final element is the end index of the desired line
|
||||
const LineRange = struct {
|
||||
@@ -1759,6 +1781,10 @@ pub fn trim(slice: anytype, comptime values_to_strip: []const u8) @TypeOf(slice)
|
||||
return slice[begin..end];
|
||||
}
|
||||
|
||||
pub fn trimSpaces(slice: anytype) @TypeOf(slice) {
|
||||
return trim(slice, &whitespace_chars);
|
||||
}
|
||||
|
||||
pub fn isAllWhitespace(slice: []const u8) bool {
|
||||
var begin: usize = 0;
|
||||
while (begin < slice.len and std.mem.indexOfScalar(u8, &whitespace_chars, slice[begin]) != null) : (begin += 1) {}
|
||||
@@ -2020,7 +2046,7 @@ pub fn concatWithLength(
|
||||
allocator: std.mem.Allocator,
|
||||
args: []const string,
|
||||
length: usize,
|
||||
) ![]u8 {
|
||||
) bun.OOM![]u8 {
|
||||
const out = try allocator.alloc(u8, length);
|
||||
var remain = out;
|
||||
for (args) |arg| {
|
||||
@@ -2034,7 +2060,7 @@ pub fn concatWithLength(
|
||||
pub fn concat(
|
||||
allocator: std.mem.Allocator,
|
||||
args: []const string,
|
||||
) ![]u8 {
|
||||
) bun.OOM![]u8 {
|
||||
var length: usize = 0;
|
||||
for (args) |arg| {
|
||||
length += arg.len;
|
||||
@@ -2342,7 +2368,6 @@ pub const toNTPath16 = paths_.toNTPath16;
|
||||
pub const toPath = paths_.toPath;
|
||||
pub const toPathMaybeDir = paths_.toPathMaybeDir;
|
||||
pub const toPathNormalized = paths_.toPathNormalized;
|
||||
pub const toWDirNormalized = paths_.toWDirNormalized;
|
||||
pub const toWDirPath = paths_.toWDirPath;
|
||||
pub const toWPath = paths_.toWPath;
|
||||
pub const toWPathMaybeDir = paths_.toWPathMaybeDir;
|
||||
|
||||
Reference in New Issue
Block a user