Skip to content

Commit

Permalink
fix(str): Fixed str.trim
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Sep 15, 2023
1 parent 637fe8e commit 266c384
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/builtin/str.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const Value = _value.Value;
pub fn trim(ctx: *NativeCtx) c_int {
const str: *ObjString = ObjString.cast(ctx.vm.peek(0).obj()).?;

var trimmed = std.mem.trim(u8, str.string, " ");
trimmed = std.mem.trim(u8, trimmed, "\t");
trimmed = std.mem.trim(u8, trimmed, "\r");
trimmed = std.mem.trim(u8, trimmed, "\n");
const trimmed = std.mem.trim(u8, str.string, " \t\r\n");

ctx.vm.push((ctx.vm.gc.copyString(trimmed) catch @panic("Could not create string")).toValue());

Expand Down
4 changes: 4 additions & 0 deletions tests/030-str.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ test "upper/lower" {

test "hex/bin" {
assert("c3fcd3d76192e4007dfb496cca67e13b".bin().hex() == "c3fcd3d76192e4007dfb496cca67e13b", message: "hex/bin");
}

test "trim" {
assert(" hello world \t\n".trim() == "hello world", message: "could trim str");
}

0 comments on commit 266c384

Please sign in to comment.