From 3a4bbfcfae0084312edaabe8c408c40bc65d45e2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 19 Jun 2020 15:01:39 +0100 Subject: [PATCH] Change `fmt.*print` behaviour to match `fmt.*println` behaviour --- core/fmt/fmt.odin | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 826840e37..c97f0f0cd 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -185,17 +185,25 @@ fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) { sbprint :: proc(buf: ^strings.Builder, args: ..any) -> string { fi: Info; - fi.buf = buf; - prev_string := false; - for arg, i in args { - is_string := arg != nil && reflect.is_string(type_info_of(arg.id)); - if i > 0 && !is_string && !prev_string { - strings.write_byte(buf, ' '); - } + // NOTE(bill): Old approach + // prev_string := false; + // for arg, i in args { + // is_string := arg != nil && reflect.is_string(type_info_of(arg.id)); + // if i > 0 && !is_string && !prev_string { + // strings.write_byte(buf, ' '); + // } + // fmt_value(&fi, args[i], 'v'); + // prev_string = is_string; + // } + // NOTE(bill, 2020-06-19): I have found that the previous approach was not what people were expecting + // and were expecting `*print` to be the same `*println` except for the added newline + // so I am going to keep the same behaviour as `*println` for `*print` + for _, i in args { + if i > 0 do strings.write_byte(buf, ' '); + fmt_value(&fi, args[i], 'v'); - prev_string = is_string; } return strings.to_string(buf^); }