MCPcopy Create free account
hub / github.com/cel-expr/cel-go / NewString

Method NewString

policy/parser.go:634–666  ·  view source on GitHub ↗

NewString creates a new ValueString from the YAML node.

(node *yaml.Node)

Source from the content-addressed store, hash-verified

632
633// NewString creates a new ValueString from the YAML node.
634func (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

Callers

nothing calls this directly

Calls 6

CollectMetadataMethod · 0.95
assertYAMLTypeMethod · 0.95
OffsetRangesMethod · 0.80
SetOffsetRangeMethod · 0.80
SnippetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected