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

Function stringMatch

internal/util/util.go:357–381  ·  view source on GitHub ↗

Searches for a partial or full match of a string If allowContains is true, the match can appear anywhere in the string. Otherwise it must start with the searchFor string

(searchFor string, searchIn string, allowContains bool)

Source from the content-addressed store, hash-verified

355// If allowContains is true, the match can appear anywhere in the string.
356// Otherwise it must start with the searchFor string
357func stringMatch(searchFor string, searchIn string, allowContains bool) (partialMatch bool, fullMatch bool) {
358
359 searchFor = strings.ToLower(searchFor)
360 searchIn = strings.ToLower(searchIn)
361
362 if allowContains {
363 for _, word := range strings.Fields(searchIn) {
364 if strings.HasPrefix(word, searchFor) {
365 if searchIn == searchFor {
366 return true, true
367 }
368 return true, false
369 }
370 }
371 }
372
373 if strings.HasPrefix(searchIn, searchFor) {
374 if searchIn == searchFor {
375 return true, true
376 }
377 return true, false
378 }
379
380 return false, false
381}
382
383func Hash(input string) string {
384 return fmt.Sprintf("%x", sha256.Sum256([]byte(input)))

Callers 2

TestStringMatchFunction · 0.85
FindMatchInFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStringMatchFunction · 0.68