gophi/core/util.go
kim (grufwub) 75cfbc0c65 gophor rewrite
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
2020-07-11 21:59:44 +01:00

23 lines
636 B
Go

package core
import (
"os"
"strings"
)
// byName and its associated functions provide a quick method of sorting FileInfos by name
type byName []os.FileInfo
func (s byName) Len() int { return len(s) }
func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
// SplitBy takes an input string and a delimiter, returning the resulting two strings from the split (ALWAYS 2)
func splitBy(input, delim string) (string, string) {
split := strings.SplitN(input, delim, 2)
if len(split) == 2 {
return split[0], split[1]
}
return split[0], ""
}