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

Function FindMatchIn

internal/util/util.go:300–352  ·  view source on GitHub ↗
(searchName string, items ...string)

Source from the content-addressed store, hash-verified

298}
299
300func FindMatchIn(searchName string, items ...string) (match string, closeMatch string) {
301
302 if searchName == `` {
303 return ``, `` // No match
304 }
305
306 searchName, searchNumber := GetMatchNumber(searchName)
307
308 var matchCt int = 0
309 var closeMatchCt int = 0
310
311 for _, i := range items {
312
313 part, full := stringMatch(searchName, i, false)
314
315 if part {
316 closeMatchCt++
317 if closeMatchCt == searchNumber {
318 closeMatch = i
319 }
320 }
321
322 if full {
323 matchCt++
324 if matchCt == searchNumber {
325 match = i
326 break
327 }
328 }
329
330 }
331
332 // If no "starts with" or "exact" matches are found, try and find the first item that contain the supplied name
333 // Note: Can't have an exact match if there was never a close match
334 if len(closeMatch) == 0 {
335 closeMatchCt = 0
336 for _, i := range items {
337 part, _ := stringMatch(searchName, i, true)
338
339 if part {
340 closeMatchCt++
341 if closeMatchCt == searchNumber {
342 closeMatch = i
343 break
344 }
345 }
346
347 }
348
349 }
350
351 return match, closeMatch
352}
353
354// Searches for a partial or full match of a string
355// If allowContains is true, the match can appear anywhere in the string.

Callers 15

onLookInputMethod · 0.92
fastTravelCommandMethod · 0.92
onLookInputMethod · 0.92
playCommandMethod · 0.92
swapToAltFunction · 0.92
characterCommandMethod · 0.92
GetDetailsFunction · 0.92
FindCorpseMethod · 0.92
FindCorpseByRefMethod · 0.92
FindByPetNameMethod · 0.92
findPlayerByNameMethod · 0.92
findMobByNameMethod · 0.92

Calls 2

GetMatchNumberFunction · 0.85
stringMatchFunction · 0.85

Tested by 1

TestFindMatchInFunction · 0.56