mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Fix and document %w verb for core:fmt
This commit is contained in:
@@ -9,6 +9,7 @@ The verbs:
|
|||||||
General:
|
General:
|
||||||
%v the value in a default format
|
%v the value in a default format
|
||||||
%#v an expanded format of %v with newlines and indentation
|
%#v an expanded format of %v with newlines and indentation
|
||||||
|
%w an Odin-syntax representation of the value
|
||||||
%T an Odin-syntax representation of the type of the value
|
%T an Odin-syntax representation of the type of the value
|
||||||
%% a literal percent sign; consumes no value
|
%% a literal percent sign; consumes no value
|
||||||
{{ a literal open brace; consumes no value
|
{{ a literal open brace; consumes no value
|
||||||
|
|||||||
+16
-6
@@ -1726,10 +1726,12 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') {
|
|||||||
|
|
||||||
et := runtime.type_info_base(info.elem)
|
et := runtime.type_info_base(info.elem)
|
||||||
|
|
||||||
if name != "" {
|
if verb != 'w' {
|
||||||
io.write_string(fi.writer, name, &fi.n)
|
if name != "" {
|
||||||
} else {
|
io.write_string(fi.writer, name, &fi.n)
|
||||||
reflect.write_type(fi.writer, type_info, &fi.n)
|
} else {
|
||||||
|
reflect.write_type(fi.writer, type_info, &fi.n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
io.write_byte(fi.writer, '{', &fi.n)
|
io.write_byte(fi.writer, '{', &fi.n)
|
||||||
defer io.write_byte(fi.writer, '}', &fi.n)
|
defer io.write_byte(fi.writer, '}', &fi.n)
|
||||||
@@ -1746,9 +1748,17 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if is_enum {
|
if is_enum {
|
||||||
|
enum_name: string
|
||||||
|
if ti_named, is_named := info.elem.variant.(runtime.Type_Info_Named); is_named {
|
||||||
|
enum_name = ti_named.name
|
||||||
|
}
|
||||||
for ev, evi in e.values {
|
for ev, evi in e.values {
|
||||||
v := u64(ev)
|
v := u64(ev)
|
||||||
if v == u64(i) {
|
if v == u64(i) {
|
||||||
|
if verb == 'w' {
|
||||||
|
io.write_string(fi.writer, enum_name, &fi.n)
|
||||||
|
io.write_byte(fi.writer, '.', &fi.n)
|
||||||
|
}
|
||||||
io.write_string(fi.writer, e.names[evi], &fi.n)
|
io.write_string(fi.writer, e.names[evi], &fi.n)
|
||||||
commas += 1
|
commas += 1
|
||||||
continue loop
|
continue loop
|
||||||
@@ -2391,7 +2401,6 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named)
|
|||||||
runtime.Type_Info_Dynamic_Array,
|
runtime.Type_Info_Dynamic_Array,
|
||||||
runtime.Type_Info_Slice,
|
runtime.Type_Info_Slice,
|
||||||
runtime.Type_Info_Struct,
|
runtime.Type_Info_Struct,
|
||||||
runtime.Type_Info_Union,
|
|
||||||
runtime.Type_Info_Enum,
|
runtime.Type_Info_Enum,
|
||||||
runtime.Type_Info_Map,
|
runtime.Type_Info_Map,
|
||||||
runtime.Type_Info_Bit_Set,
|
runtime.Type_Info_Bit_Set,
|
||||||
@@ -2498,8 +2507,9 @@ fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Matrix
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Printed in Row-Major layout to match text layout
|
// Printed in Row-Major layout to match text layout
|
||||||
|
row_separator := ", " if verb == 'w' else "; "
|
||||||
for row in 0..<info.row_count {
|
for row in 0..<info.row_count {
|
||||||
if row > 0 { io.write_string(fi.writer, "; ", &fi.n) }
|
if row > 0 { io.write_string(fi.writer, row_separator, &fi.n) }
|
||||||
for col in 0..<info.column_count {
|
for col in 0..<info.column_count {
|
||||||
if col > 0 { io.write_string(fi.writer, ", ", &fi.n) }
|
if col > 0 { io.write_string(fi.writer, ", ", &fi.n) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user