From 507722954c0390840d1ff0b0e8770428c3252114 Mon Sep 17 00:00:00 2001 From: Lucas Perlind Date: Wed, 2 Mar 2022 16:15:53 +1100 Subject: Improve core:fmt formatting * Strings will respect widths smaller than the string's length * Strings are right justified by default like integers * Strings accept '-' flag to be left justified * Booleans will be formatted like strings * Enums will be formatted like strings --- core/fmt/fmt.odin | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index d6c1894b7..d006d0ef8 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -605,7 +605,7 @@ fmt_bad_verb :: proc(using fi: ^Info, verb: rune) { fmt_bool :: proc(using fi: ^Info, b: bool, verb: rune) { switch verb { case 't', 'v': - io.write_string(writer, b ? "true" : "false", &fi.n) + fmt_string(fi, b ? "true" : "false", 's') case: fmt_bad_verb(fi, verb) } @@ -943,11 +943,27 @@ fmt_float :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune) { fmt_string :: proc(fi: ^Info, s: string, verb: rune) { switch verb { case 's', 'v': - io.write_string(fi.writer, s, &fi.n) - if fi.width_set && len(s) < fi.width { - for _ in 0.. len(s) { + if fi.minus { + io.write_string(fi.writer, s, &fi.n) + } + + for _ in 0..