MCPcopy Create free account
hub / github.com/campoy/embedmd / fields

Function fields

embedmd/command.go:67–87  ·  view source on GitHub ↗

fields returns a list of the groups of text separated by blanks, keeping all text surrounded by / as a group.

(s string)

Source from the content-addressed store, hash-verified

65// fields returns a list of the groups of text separated by blanks,
66// keeping all text surrounded by / as a group.
67func fields(s string) ([]string, error) {
68 var args []string
69
70 for s = strings.TrimSpace(s); len(s) > 0; s = strings.TrimSpace(s) {
71 if s[0] == '/' {
72 sep := nextSlash(s[1:])
73 if sep < 0 {
74 return nil, errors.New("unbalanced /")
75 }
76 args, s = append(args, s[:sep+2]), s[sep+2:]
77 } else {
78 sep := strings.IndexByte(s[1:], ' ')
79 if sep < 0 {
80 return append(args, s), nil
81 }
82 args, s = append(args, s[:sep+1]), s[sep+1:]
83 }
84 }
85
86 return args, nil
87}
88
89// nextSlash will find the index of the next unescaped slash in a string.
90func nextSlash(s string) int {

Callers 1

parseCommandFunction · 0.85

Calls 1

nextSlashFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…