NewString creates a new ValueString from the YAML node.
(node *yaml.Node)
| 632 | |
| 633 | // NewString creates a new ValueString from the YAML node. |
| 634 | func (p *parserImpl) NewString(node *yaml.Node) ValueString { |
| 635 | id := p.CollectMetadata(node) |
| 636 | nodeType := p.assertYAMLType(id, node, yamlString, yamlText) |
| 637 | if nodeType == nil { |
| 638 | return ValueString{ID: id, Value: "*error*"} |
| 639 | } |
| 640 | if *nodeType == yamlText { |
| 641 | return ValueString{ID: id, Value: node.Value} |
| 642 | } |
| 643 | if node.Style == yaml.FoldedStyle || node.Style == yaml.LiteralStyle { |
| 644 | col := node.Column |
| 645 | line := node.Line |
| 646 | txt, found := p.src.Snippet(line) |
| 647 | indent := "" |
| 648 | for len(indent) < col-1 { |
| 649 | indent += " " |
| 650 | } |
| 651 | var raw strings.Builder |
| 652 | for found && strings.HasPrefix(txt, indent) { |
| 653 | line++ |
| 654 | raw.WriteString(txt) |
| 655 | txt, found = p.src.Snippet(line) |
| 656 | if found && strings.HasPrefix(txt, indent) { |
| 657 | raw.WriteString("\n") |
| 658 | } |
| 659 | } |
| 660 | offset := p.info.OffsetRanges()[p.id] |
| 661 | offsetStart := offset.Start - (int32(node.Column) - 1) |
| 662 | p.info.SetOffsetRange(p.id, ast.OffsetRange{Start: offsetStart, Stop: offsetStart}) |
| 663 | return ValueString{ID: id, Value: raw.String()} |
| 664 | } |
| 665 | return ValueString{ID: id, Value: node.Value} |
| 666 | } |
| 667 | |
| 668 | // newStrictString creates a new ValueString from the YAML node, but as a string with no special |
| 669 | // source position information. Intended for use in descriptions, where the string is just |
nothing calls this directly
no test coverage detected