MCPcopy Create free account
hub / github.com/barnybug/cli53 / safeSplit

Function safeSplit

internal/features/step_definitions.go:142–169  ·  view source on GitHub ↗

Split on whitespace, but leave quoted strings in tact

(s string)

Source from the content-addressed store, hash-verified

140
141// Split on whitespace, but leave quoted strings in tact
142func safeSplit(s string) []string {
143 split := strings.Split(s, " ")
144
145 var result []string
146 var inquote string
147 var block string
148 for _, i := range split {
149 if inquote == "" {
150 if strings.HasPrefix(i, "'") || strings.HasPrefix(i, "\"") {
151 inquote = string(i[0])
152 block = strings.TrimPrefix(i, inquote) + " "
153 } else {
154 result = append(result, i)
155 }
156 } else {
157 if !strings.HasSuffix(i, inquote) {
158 block += i + " "
159 } else {
160 block += strings.TrimSuffix(i, inquote)
161 inquote = ""
162 result = append(result, block)
163 block = ""
164 }
165 }
166 }
167
168 return result
169}
170
171func domain(s string) string {
172 domain := World["$domain"].(string)

Callers 2

executeFunction · 0.85
initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected