elvish/pkg/strutil/subseq.go
Qi Xiao ee62608e88 pkg: Move string utilities from util/ to strutil/.
Also remove unused functions.

There were two (correct) implementations of deciding whether a string has
another string as a subsequence; keep the more performant one.
2020-09-03 05:08:01 +01:00

18 lines
413 B
Go

package strutil
import "strings"
// HasSubseq determines whether s has t as its subsequence. A string t is a
// subsequence of a string s if and only if there is a possible sequence of
// steps of deleting characters from s that result in t.
func HasSubseq(s, t string) bool {
for _, p := range t {
i := strings.IndexRune(s, p)
if i == -1 {
return false
}
s = s[i+len(string(p)):]
}
return true
}