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

Method node

encode.go:432–577  ·  encode.go::encoder.node
(node *Node, tail string)

Source from the content-addressed store, hash-verified

430}
431
432func (e *encoder) node(node *Node, tail string) {
433 // Zero nodes behave as nil.
434 if node.Kind == 0 && node.IsZero() {
435 e.nilv()
436 return
437 }
438
439 // If the tag was not explicitly requested, and dropping it won't change the
440 // implicit tag of the value, don't include it in the presentation.
441 var tag = node.Tag
442 var stag = shortTag(tag)
443 var forceQuoting bool
444 if tag != "" && node.Style&TaggedStyle == 0 {
445 if node.Kind == ScalarNode {
446 if stag == strTag && node.Style&(SingleQuotedStyle|DoubleQuotedStyle|LiteralStyle|FoldedStyle) != 0 {
447 tag = ""
448 } else {
449 rtag, _ := resolve("", node.Value)
450 if rtag == stag {
451 tag = ""
452 } else if stag == strTag {
453 tag = ""
454 forceQuoting = true
455 }
456 }
457 } else {
458 var rtag string
459 switch node.Kind {
460 case MappingNode:
461 rtag = mapTag
462 case SequenceNode:
463 rtag = seqTag
464 }
465 if rtag == stag {
466 tag = ""
467 }
468 }
469 }
470
471 switch node.Kind {
472 case DocumentNode:
473 yaml_document_start_event_initialize(&e.event, nil, nil, true)
474 e.event.head_comment = []byte(node.HeadComment)
475 e.emit()
476 for _, node := range node.Content {
477 e.node(node, "")
478 }
479 yaml_document_end_event_initialize(&e.event, true)
480 e.event.foot_comment = []byte(node.FootComment)
481 e.emit()
482
483 case SequenceNode:
484 style := yaml_BLOCK_SEQUENCE_STYLE
485 if node.Style&FlowStyle != 0 {
486 style = yaml_FLOW_SEQUENCE_STYLE
487 }
488 e.must(yaml_sequence_start_event_initialize(&e.event, []byte(node.Anchor), []byte(longTag(tag)), tag == "", style))
489 e.event.head_comment = []byte(node.HeadComment)

Callers 1

nodevMethod · 0.95

Calls 15

nilvMethod · 0.95
emitMethod · 0.95
mustMethod · 0.95
emitScalarMethod · 0.95
shortTagFunction · 0.85
resolveFunction · 0.85
longTagFunction · 0.85

Tested by

no test coverage detected