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)
| 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. |
| 471 | func (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 |