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

Method NewString

policy/parser.go:676–708  ·  view source on GitHub ↗

NewString creates a new ValueString from the YAML node.

(node *yaml.Node)

Source from the content-addressed store, hash-verified

674
675// NewString creates a new ValueString from the YAML node.
676func (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

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