diff options
| author | gingerBill <bill@gingerbill.org> | 2020-11-20 16:25:11 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-11-20 16:25:11 +0000 |
| commit | a14ea5b2b5068e679a961d0fd43e84eea593e2da (patch) | |
| tree | 534e73f8e75c9f17fd04a293c591287dfc633c4f | |
| parent | 63e4a2341f1409eec1f2e58036cd01b24b66b8f0 (diff) | |
Add support for %s and %q for [dynamic]byte
| -rw-r--r-- | core/fmt/fmt.odin | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 79c62cc17..ec664a2a9 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1633,13 +1633,15 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } case runtime.Type_Info_Dynamic_Array: - if verb == 'p' { - slice := cast(^mem.Raw_Dynamic_Array)v.data; - fmt_pointer(fi, slice.data, 'p'); + array := cast(^mem.Raw_Dynamic_Array)v.data; + if (verb == 's' || verb == 'q') && reflect.is_byte(info.elem) { + s := strings.string_from_ptr((^byte)(array.data), array.len); + fmt_string(fi, s, verb); + } else if verb == 'p' { + fmt_pointer(fi, array.data, 'p'); } else { strings.write_byte(fi.buf, '['); defer strings.write_byte(fi.buf, ']'); - array := cast(^mem.Raw_Dynamic_Array)v.data; for i in 0..<array.len { if i > 0 { strings.write_string(fi.buf, ", "); } |