Align ignore syntax of json tags with fmt, cbor

This commit is contained in:
VladPavliuk
2024-07-14 00:21:05 +03:00
parent 64ae99f016
commit 76fe5d1346
2 changed files with 7 additions and 4 deletions

View File

@@ -406,16 +406,19 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
ti := runtime.type_info_base(type_info_of(v.id))
info := ti.variant.(runtime.Type_Info_Struct)
first_iteration := true
fields_loop: for name, i in info.names {
for name, i in info.names {
omitempty := false
json_name, extra := json_name_from_tag_value(reflect.struct_tag_get(reflect.Struct_Tag(info.tags[i]), "json"))
if json_name == "-" {
continue
}
for flag in strings.split_iterator(&extra, ",") {
switch flag {
case "omitempty":
omitempty = true
case "ignore":
continue fields_loop
}
}

View File

@@ -373,7 +373,7 @@ utf8_string_of_multibyte_characters :: proc(t: ^testing.T) {
@test
struct_with_ignore_tags :: proc(t: ^testing.T) {
My_Struct :: struct {
a: string `json:"_,ignore"`,
a: string `json:"-"`,
}
my_struct := My_Struct{