github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/fuzzy/fuzzytext/simple.go (about)

     1  package fuzzytext
     2  
     3  import (
     4  	"unicode"
     5  	"unicode/utf8"
     6  )
     7  
     8  func MatchSimple(p, s string) (match bool) {
     9  	pch, pn := utf8.DecodeRuneInString(p)
    10  	if pch == utf8.RuneError {
    11  		return false
    12  	}
    13  	p = p[pn:]
    14  	pch = unicode.ToLower(pch)
    15  
    16  	for _, sch := range s {
    17  		sch = unicode.ToLower(sch)
    18  		if sch != pch {
    19  			continue
    20  		}
    21  
    22  		pch, pn = utf8.DecodeRuneInString(p)
    23  		if pch == utf8.RuneError {
    24  			return pn == 0
    25  		}
    26  		p = p[pn:]
    27  		pch = unicode.ToLower(pch)
    28  	}
    29  
    30  	return false
    31  }