elvish/pkg/strutil/eol_sol.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

21 lines
398 B
Go

package strutil
import (
"strings"
)
// FindFirstEOL returns the index of the first '\n'. When there is no '\n', the
// length of s is returned.
func FindFirstEOL(s string) int {
eol := strings.IndexRune(s, '\n')
if eol == -1 {
eol = len(s)
}
return eol
}
// FindLastSOL returns an index just after the last '\n'.
func FindLastSOL(s string) int {
return strings.LastIndex(s, "\n") + 1
}