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

Method SetString

yaml.go:471–483  ·  view source on GitHub ↗

SetString is a convenience function that sets the node to a string value and defines its style in a pleasant way depending on its content.

(s string)

Source from the content-addressed store, hash-verified

469// SetString is a convenience function that sets the node to a string value
470// and defines its style in a pleasant way depending on its content.
471func (n *Node) SetString(s string) {
472 n.Kind = ScalarNode
473 if utf8.ValidString(s) {
474 n.Value = s
475 n.Tag = strTag
476 } else {
477 n.Value = encodeBase64(s)
478 n.Tag = binaryTag
479 }
480 if strings.Contains(n.Value, "\n") {
481 n.Style = LiteralStyle
482 }
483}
484
485// --------------------------------------------------------------------------
486// Maintain a mapping of keys to structure field indexes

Callers 2

TestSetStringMethod · 0.95
scalarMethod · 0.80

Calls 1

encodeBase64Function · 0.85

Tested by 1

TestSetStringMethod · 0.76