| ... | ... | @@ -1321,7 +1321,6 @@ pub const Value = union(enum) { |
| 1321 | 1321 | try out_stream.writeByte(','); |
| 1322 | 1322 | } |
| 1323 | 1323 | if (child_options.whitespace) |child_whitespace| { |
| 1324 | | try out_stream.writeByte('\n'); |
| 1325 | 1324 | try child_whitespace.outputIndent(out_stream); |
| 1326 | 1325 | } |
| 1327 | 1326 | |
| ... | ... | @@ -1336,7 +1335,6 @@ pub const Value = union(enum) { |
| 1336 | 1335 | } |
| 1337 | 1336 | if (field_output) { |
| 1338 | 1337 | if (options.whitespace) |whitespace| { |
| 1339 | | try out_stream.writeByte('\n'); |
| 1340 | 1338 | try whitespace.outputIndent(out_stream); |
| 1341 | 1339 | } |
| 1342 | 1340 | } |
| ... | ... | @@ -2943,6 +2941,7 @@ pub const StringifyOptions = struct { |
| 2943 | 2941 | indent: union(enum) { |
| 2944 | 2942 | Space: u8, |
| 2945 | 2943 | Tab: void, |
| 2944 | None: void, |
| 2946 | 2945 | } = .{ .Space = 4 }, |
| 2947 | 2946 | |
| 2948 | 2947 | /// After a colon, should whitespace be inserted? |
| ... | ... | @@ -2963,7 +2962,9 @@ pub const StringifyOptions = struct { |
| 2963 | 2962 | char = '\t'; |
| 2964 | 2963 | n_chars = 1; |
| 2965 | 2964 | }, |
| 2965 | .None => return, |
| 2966 | 2966 | } |
| 2967 | try out_stream.writeByte('\n'); |
| 2967 | 2968 | n_chars *= whitespace.indent_level; |
| 2968 | 2969 | try out_stream.writeByteNTimes(char, n_chars); |
| 2969 | 2970 | } |
| ... | ... | @@ -3139,7 +3140,6 @@ pub fn stringify( |
| 3139 | 3140 | try out_stream.writeByte(','); |
| 3140 | 3141 | } |
| 3141 | 3142 | if (child_options.whitespace) |child_whitespace| { |
| 3142 | | try out_stream.writeByte('\n'); |
| 3143 | 3143 | try child_whitespace.outputIndent(out_stream); |
| 3144 | 3144 | } |
| 3145 | 3145 | try outputJsonString(Field.name, options, out_stream); |
| ... | ... | @@ -3154,7 +3154,6 @@ pub fn stringify( |
| 3154 | 3154 | } |
| 3155 | 3155 | if (field_output) { |
| 3156 | 3156 | if (options.whitespace) |whitespace| { |
| 3157 | | try out_stream.writeByte('\n'); |
| 3158 | 3157 | try whitespace.outputIndent(out_stream); |
| 3159 | 3158 | } |
| 3160 | 3159 | } |
| ... | ... | @@ -3190,14 +3189,12 @@ pub fn stringify( |
| 3190 | 3189 | try out_stream.writeByte(','); |
| 3191 | 3190 | } |
| 3192 | 3191 | if (child_options.whitespace) |child_whitespace| { |
| 3193 | | try out_stream.writeByte('\n'); |
| 3194 | 3192 | try child_whitespace.outputIndent(out_stream); |
| 3195 | 3193 | } |
| 3196 | 3194 | try stringify(x, child_options, out_stream); |
| 3197 | 3195 | } |
| 3198 | 3196 | if (value.len != 0) { |
| 3199 | 3197 | if (options.whitespace) |whitespace| { |
| 3200 | | try out_stream.writeByte('\n'); |
| 3201 | 3198 | try whitespace.outputIndent(out_stream); |
| 3202 | 3199 | } |
| 3203 | 3200 | } |
| ... | ... | @@ -3368,6 +3365,23 @@ test "stringify struct with indentation" { |
| 3368 | 3365 | }, |
| 3369 | 3366 | }, |
| 3370 | 3367 | ); |
| 3368 | try teststringify( |
| 3369 | \\{"foo":42,"bar":[1,2,3]} |
| 3370 | , |
| 3371 | struct { |
| 3372 | foo: u32, |
| 3373 | bar: [3]u32, |
| 3374 | }{ |
| 3375 | .foo = 42, |
| 3376 | .bar = .{ 1, 2, 3 }, |
| 3377 | }, |
| 3378 | StringifyOptions{ |
| 3379 | .whitespace = .{ |
| 3380 | .indent = .None, |
| 3381 | .separator = false, |
| 3382 | }, |
| 3383 | }, |
| 3384 | ); |
| 3371 | 3385 | } |
| 3372 | 3386 | |
| 3373 | 3387 | test "stringify struct with void field" { |