MCPcopy
hub / github.com/go-yaml/yaml / yaml_emitter_emit_block_mapping_value

Function yaml_emitter_emit_block_mapping_value

emitterc.go:803–848  ·  view source on GitHub ↗

Expect a block value node.

(emitter *yaml_emitter_t, event *yaml_event_t, simple bool)

Source from the content-addressed store, hash-verified

801
802// Expect a block value node.
803func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool {
804 if simple {
805 if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) {
806 return false
807 }
808 } else {
809 if !yaml_emitter_write_indent(emitter) {
810 return false
811 }
812 if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, true) {
813 return false
814 }
815 }
816 if len(emitter.key_line_comment) > 0 {
817 // [Go] Line comments are generally associated with the value, but when there's
818 // no value on the same line as a mapping key they end up attached to the
819 // key itself.
820 if event.typ == yaml_SCALAR_EVENT {
821 if len(emitter.line_comment) == 0 {
822 // A scalar is coming and it has no line comments by itself yet,
823 // so just let it handle the line comment as usual. If it has a
824 // line comment, we can't have both so the one from the key is lost.
825 emitter.line_comment = emitter.key_line_comment
826 emitter.key_line_comment = nil
827 }
828 } else if event.sequence_style() != yaml_FLOW_SEQUENCE_STYLE && (event.typ == yaml_MAPPING_START_EVENT || event.typ == yaml_SEQUENCE_START_EVENT) {
829 // An indented block follows, so write the comment right now.
830 emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
831 if !yaml_emitter_process_line_comment(emitter) {
832 return false
833 }
834 emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
835 }
836 }
837 emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE)
838 if !yaml_emitter_emit_node(emitter, event, false, false, true, false) {
839 return false
840 }
841 if !yaml_emitter_process_line_comment(emitter) {
842 return false
843 }
844 if !yaml_emitter_process_foot_comment(emitter) {
845 return false
846 }
847 return true
848}
849
850func yaml_emitter_silent_nil_event(emitter *yaml_emitter_t, event *yaml_event_t) bool {
851 return event.typ == yaml_SCALAR_EVENT && event.implicit && !emitter.canonical && len(emitter.scalar_data.value) == 0

Callers 1

Tested by

no test coverage detected