Skip to content

Commit

Permalink
Use LITERAL_SCALAR_STYLE for space breaks unless they are trailing
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Nov 14, 2024
1 parent bc8a41d commit 674ebf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool {
// Check if we need to accumulate more events before emitting.
//
// We accumulate extra
// - 1 event for DOCUMENT-START
// - 2 events for SEQUENCE-START
// - 3 events for MAPPING-START
//
// - 1 event for DOCUMENT-START
// - 2 events for SEQUENCE-START
// - 3 events for MAPPING-START
func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool {
if emitter.events_head == len(emitter.events) {
return true
Expand Down Expand Up @@ -241,7 +240,7 @@ func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool
emitter.indent += 2
} else {
// Everything else aligns to the chosen indentation.
emitter.indent = emitter.best_indent*((emitter.indent+emitter.best_indent)/emitter.best_indent)
emitter.indent = emitter.best_indent * ((emitter.indent + emitter.best_indent) / emitter.best_indent)
}
}
return true
Expand Down Expand Up @@ -1362,6 +1361,10 @@ func yaml_emitter_analyze_scalar(emitter *yaml_emitter_t, value []byte) bool {
previous_break = false
}

if !is_blankz(value, i) {
space_break = false // only count space breaks if they are after all the visibile characters (so trailing spaces at the end of the value)
}

// [Go]: Why 'z'? Couldn't be the end of the string as that's the loop condition.
preceded_by_whitespace = is_blankz(value, i)
}
Expand Down
2 changes: 2 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ var marshalerTests = []struct {
{"_: 10\n", 10},
{"_: null\n", nil},
{"_: BAR!\n", "BAR!"},
{"_:\n lines: |-\n one\n two\n three\n", map[interface{}]interface{}{"lines": "one\ntwo\nthree"}},
{"_:\n lines: |-\n one\n two \n three\n", map[interface{}]interface{}{"lines": "one\ntwo \nthree"}},
}

type marshalerType struct {
Expand Down

0 comments on commit 674ebf2

Please sign in to comment.