NewString creates a new ValueString from the YAML node.
(node *yaml.Node)
| 674 | |
| 675 | // NewString creates a new ValueString from the YAML node. |
| 676 | func (p *parserImpl) NewString(node *yaml.Node) ValueString { |
| 677 | id := p.CollectMetadata(node) |
| 678 | nodeType := p.assertYAMLType(id, node, yamlString, yamlText) |
| 679 | if nodeType == nil { |
| 680 | return ValueString{ID: id, Value: "*error*"} |
| 681 | } |
| 682 | if *nodeType == yamlText { |
| 683 | return ValueString{ID: id, Value: node.Value} |
| 684 | } |
| 685 | if node.Style == yaml.FoldedStyle || node.Style == yaml.LiteralStyle { |
| 686 | col := node.Column |
| 687 | line := node.Line |
| 688 | txt, found := p.src.Snippet(line) |
| 689 | indent := "" |
| 690 | for len(indent) < col-1 { |
| 691 | indent += " " |
| 692 | } |
| 693 | var raw strings.Builder |
| 694 | for found && strings.HasPrefix(txt, indent) { |
| 695 | line++ |
| 696 | raw.WriteString(txt) |
| 697 | txt, found = p.src.Snippet(line) |
| 698 | if found && strings.HasPrefix(txt, indent) { |
| 699 | raw.WriteString("\n") |
| 700 | } |
| 701 | } |
| 702 | offset := p.info.OffsetRanges()[p.id] |
| 703 | offsetStart := offset.Start - (int32(node.Column) - 1) |
| 704 | p.info.SetOffsetRange(p.id, ast.OffsetRange{Start: offsetStart, Stop: offsetStart}) |
| 705 | return ValueString{ID: id, Value: raw.String()} |
| 706 | } |
| 707 | return ValueString{ID: id, Value: node.Value} |
| 708 | } |
| 709 | |
| 710 | // newStrictString creates a new ValueString from the YAML node, but as a string with no special |
| 711 | // source position information. Intended for use in descriptions, where the string is just |
nothing calls this directly
no test coverage detected