aboutsummaryrefslogtreecommitdiff
path: root/src/install/semver.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-12-01 04:49:57 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-12-16 19:18:51 -0800
commit118ed4d2abdc33afe86b8f7c371caed08bfe6c73 (patch)
tree2e3269c63305c55ea5ca3d61ac10b8d6101744fe /src/install/semver.zig
parent9fcd2c53c874c27f143c16d48618b2c81be01d55 (diff)
downloadbun-118ed4d2abdc33afe86b8f7c371caed08bfe6c73.tar.gz
bun-118ed4d2abdc33afe86b8f7c371caed08bfe6c73.tar.zst
bun-118ed4d2abdc33afe86b8f7c371caed08bfe6c73.zip
[bun install] Generate a lockfile
Diffstat (limited to 'src/install/semver.zig')
-rw-r--r--src/install/semver.zig34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/install/semver.zig b/src/install/semver.zig
index 6e36f2c2d..d95ca2f52 100644
--- a/src/install/semver.zig
+++ b/src/install/semver.zig
@@ -128,6 +128,19 @@ pub const Version = extern struct {
tag: Tag = Tag{},
// raw: RawType = RawType{},
+ pub fn cloneInto(this: Version, slice: []const u8, buf: []u8) Version {
+ return Version{
+ .major = this.major,
+ .minor = this.minor,
+ .patch = this.patch,
+ .tag = this.tag.cloneInto(slice, buf),
+ };
+ }
+
+ pub inline fn len(this: *const Version) u32 {
+ return this.tag.build.len + this.tag.pre.len;
+ }
+
pub fn fmt(this: Version, input: string) Formatter {
return Formatter{ .version = this, .input = input };
}
@@ -137,7 +150,7 @@ pub const Version = extern struct {
if (this.tag.hasBuild()) builder.count(this.tag.build.slice(buf));
}
- pub fn clone(this: Version, comptime StringBuilder: type, builder: StringBuilder) Version {
+ pub fn clone(this: Version, buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) Version {
var that = this;
if (this.tag.hasPre()) that.tag.pre = builder.append(ExternalString, this.tag.pre.slice(buf));
@@ -214,6 +227,25 @@ pub const Version = extern struct {
pre: ExternalString = ExternalString{},
build: ExternalString = ExternalString{},
+ pub fn cloneInto(this: Tag, slice: []const u8, buf: []u8) Tag {
+ const pre_slice = this.pre.slice(slice);
+ const build_slice = this.build.slice(slice);
+ std.mem.copy(u8, buf, pre_slice);
+ std.mem.copy(u8, buf[pre_slice.len..], build_slice);
+ return Tag{
+ .pre = .{
+ .off = 0,
+ .len = this.pre.len,
+ .hash = this.pre.hash,
+ },
+ .build = .{
+ .off = this.pre.len,
+ .len = this.build.len,
+ .hash = this.build.hash,
+ },
+ };
+ }
+
pub inline fn hasPre(this: Tag) bool {
return this.pre.len > 0;
}