mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Use bun.String for ZigException (#3451)
* Use `bun.String` for `ZigException` * woopsie --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -247,6 +247,26 @@ pub const String = extern struct {
|
||||
extern fn BunString__fromLatin1(bytes: [*]const u8, len: usize) String;
|
||||
extern fn BunString__fromBytes(bytes: [*]const u8, len: usize) String;
|
||||
|
||||
pub fn toOwnedSlice(this: String, allocator: std.mem.Allocator) ![]u8 {
|
||||
switch (this.tag) {
|
||||
.ZigString => return try this.value.ZigString.toOwnedSlice(allocator),
|
||||
.WTFStringImpl => {
|
||||
var utf8_slice = this.value.WTFStringImpl.toUTF8(allocator);
|
||||
|
||||
if (utf8_slice.allocator.get()) |alloc| {
|
||||
if (isWTFAllocator(alloc)) {
|
||||
return @constCast((try utf8_slice.clone(allocator)).slice());
|
||||
}
|
||||
}
|
||||
|
||||
return @constCast(utf8_slice.slice());
|
||||
},
|
||||
.StaticZigString => return try this.value.StaticZigString.toOwnedSlice(allocator),
|
||||
.Empty => return &[_]u8{},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn createLatin1(bytes: []const u8) String {
|
||||
JSC.markBinding(@src());
|
||||
return BunString__fromLatin1(bytes.ptr, bytes.len);
|
||||
@@ -429,6 +449,10 @@ pub const String = extern struct {
|
||||
return .latin1;
|
||||
}
|
||||
|
||||
pub fn githubAction(self: String) ZigString.GithubActionFormatter {
|
||||
return self.toZigString().githubAction();
|
||||
}
|
||||
|
||||
pub fn byteSlice(this: String) []const u8 {
|
||||
return switch (this.tag) {
|
||||
.ZigString, .StaticZigString => this.value.ZigString.byteSlice(),
|
||||
|
||||
Reference in New Issue
Block a user