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

Function splitImpl

cel/prompt.go:35–61  ·  view source on GitHub ↗

splitImpl splits a string into a list of strings. Normalizes extracted comments (trim common prefix whitespace and extra trailing newlines).

(str string)

Source from the content-addressed store, hash-verified

33//
34// Normalizes extracted comments (trim common prefix whitespace and extra trailing newlines).
35func splitImpl(str string) []string {
36 str = strings.TrimRight(str, " \n\t\r")
37 out := strings.Split(str, "\n")
38 if len(out) == 0 {
39 return nil
40 }
41 negative := strings.TrimLeft(out[0], " \t")
42 lenNegative := len(negative)
43 lenOut := len(out[0])
44 if lenNegative == lenOut {
45 return out
46 }
47 prefix := out[0][:lenOut-lenNegative]
48 trimmed := make([]string, len(out))
49 for i, line := range out {
50 if line == "" {
51 trimmed[i] = ""
52 continue
53 }
54 if !strings.HasPrefix(line, prefix) {
55 return out
56 }
57 trimmed[i] = strings.TrimPrefix(line, prefix)
58 }
59
60 return trimmed
61}
62
63// AuthoringPrompt creates a prompt template from a CEL environment for the purpose of AI-assisted authoring.
64func AuthoringPrompt(env *Env) (*Prompt, error) {

Callers 1

Calls

no outgoing calls

Tested by 1