From 266c3846e4fdab23636ce65c9027fd4ab2687adc Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 15 Sep 2023 15:07:01 +0200 Subject: [PATCH] fix(str): Fixed str.trim --- src/builtin/str.zig | 5 +---- tests/030-str.buzz | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/builtin/str.zig b/src/builtin/str.zig index 868c4833..09426600 100644 --- a/src/builtin/str.zig +++ b/src/builtin/str.zig @@ -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()); diff --git a/tests/030-str.buzz b/tests/030-str.buzz index c6160ff8..a133fc51 100644 --- a/tests/030-str.buzz +++ b/tests/030-str.buzz @@ -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"); } \ No newline at end of file