MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SplitButRespectQuotes

Function SplitButRespectQuotes

internal/util/util.go:254–278  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

252}
253
254func SplitButRespectQuotes(s string) []string {
255
256 // This regex matches either a quoted string (with either single or double quotes) or a non-space sequence.
257 // For example, for the input: `hello "my name" is 'Sammy'`
258 // It matches: [`hello", ""my name"", "is", "'Sammy'`]
259 re := regexp.MustCompile(`("[^"]*")|('[^']*')|\S+`)
260 matches := re.FindAllString(s, -1)
261 finalMatches := make([]string, 0, 1)
262
263 // Remove quotes around the matches, if they exist
264 for _, match := range matches {
265
266 match = strings.TrimSpace(match)
267
268 if strings.HasPrefix(match, `"`) && strings.HasSuffix(match, `"`) ||
269 strings.HasPrefix(match, `'`) && strings.HasSuffix(match, `'`) {
270 str := strings.TrimSpace(match[1 : len(match)-1])
271 finalMatches = append(finalMatches, str)
272 } else {
273 finalMatches = append(finalMatches, match)
274 }
275 }
276
277 return finalMatches
278}
279
280// accepts an input and splits it along a # if any.
281// By default returns the full string and 1 as the number.

Callers 15

zombieCommandMethod · 0.92
storageCommandMethod · 0.92
userBuryCommandMethod · 0.92
mobBuryCommandMethod · 0.92
followUserCommandMethod · 0.92
followMobCommandMethod · 0.92
auctionCommandMethod · 0.92
FindNounMethod · 0.92
ExpandCommandFunction · 0.92
PutFunction · 0.92
PathtoFunction · 0.92
ShootFunction · 0.92

Calls

no outgoing calls

Tested by 1