github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/elvish/util/subseq.go (about) 1 package util 2 3 import "unicode/utf8" 4 5 // HasSubseq determines whether s has t as its subsequence. A string t is a 6 // subsequence of a string s if and only if there is a possible sequence of 7 // steps of deleting characters from s that result in t. 8 func HasSubseq(s, t string) bool { 9 i, j := 0, 0 10 for i < len(s) && j < len(t) { 11 s0, di := utf8.DecodeRuneInString(s[i:]) 12 t0, dj := utf8.DecodeRuneInString(t[j:]) 13 i += di 14 if s0 == t0 { 15 j += dj 16 } 17 } 18 return j == len(t) 19 }