mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
ee62608e88
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.
18 lines
413 B
Go
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
|
|
}
|