diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-01-27 23:02:55 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-01-27 23:02:55 +0000 |
| commit | 31aacd5bf435224c7d8f9b19359175d3e6d25660 (patch) | |
| tree | ab9d62de198d9874e1afb7212ab3feb46fde4f01 /core | |
| parent | 92453369c5558feaaaa116fbc54968b087e1aeab (diff) | |
Fix parsing for block/if expression within if/for/etc. statementsv0.0.6
Diffstat (limited to 'core')
| -rw-r--r-- | core/fmt.odin | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/core/fmt.odin b/core/fmt.odin index bd11d05e0..fe822b4c8 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -421,9 +421,7 @@ fmt_write_padding :: proc(fi: ^Fmt_Info, width: int) { fmt_integer :: proc(fi: ^Fmt_Info, u: u64, base: int, signed: bool, digits: string) { negative := signed && cast(i64)u < 0; - if negative { - u = -u; - } + u = abs(u); buf: [256]byte; if fi.width_set || fi.prec_set { width := fi.width + fi.prec + 3; @@ -504,14 +502,16 @@ fmt_integer :: proc(fi: ^Fmt_Info, u: u64, base: int, signed: bool, digits: stri buffer_write(fi.buf, buf[i:]); } else { width := fi.width - utf8.rune_count(cast(string)buf[i:]); - if fi.minus { - // Right pad - buffer_write(fi.buf, buf[i:]); - fmt_write_padding(fi, width); - } else { - // Left pad - fmt_write_padding(fi, width); - buffer_write(fi.buf, buf[i:]); + if width > 0 { + if fi.minus { + // Right pad + buffer_write(fi.buf, buf[i:]); + fmt_write_padding(fi, width); + } else { + // Left pad + fmt_write_padding(fi, width); + buffer_write(fi.buf, buf[i:]); + } } } @@ -574,8 +574,16 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) { signed := v < 0; v = abs(v); + if signed { + buffer_write_byte(fi.buf, '-'); + } + val := cast(u64)v; - fmt_integer(fi, val, 10, signed, __DIGITS_LOWER); + fi.minus = false; + fi.width = 0; + fi.prec = 0; + // TODO(bill): Write integer to buffer than use this crap + fmt_integer(fi, val, 10, false, __DIGITS_LOWER); if fi.hash || prec > 0 { arg := v - cast(f64)val; |