You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
958 B
Go
45 lines
958 B
Go
package staros
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"strings"
|
|
)
|
|
|
|
func splitBy(data, sep string) map[string]string {
|
|
res := make(map[string]string)
|
|
lists := strings.Split(data, "\n")
|
|
for _, v := range lists {
|
|
list := strings.SplitN(v, sep, 2)
|
|
if len(list) != 2 {
|
|
continue
|
|
}
|
|
res[strings.TrimSpace(list[0])] = strings.TrimSpace(list[1])
|
|
}
|
|
return res
|
|
}
|
|
|
|
// 横向替换ASCII<9>
|
|
func ReplaceByte9(data string) string {
|
|
return string(bytes.ReplaceAll([]byte(data), []byte{9}, []byte(" ")))
|
|
}
|
|
|
|
func splitBySpace(data string) []string {
|
|
data = string(bytes.ReplaceAll([]byte(data), []byte{9}, []byte(" ")))
|
|
nomorespace := func(data string) string {
|
|
return strings.ReplaceAll(data, " ", " ")
|
|
}
|
|
for strings.Index(data, " ") >= 0 {
|
|
data = nomorespace(data)
|
|
}
|
|
return strings.Split(data, " ")
|
|
}
|
|
|
|
func readAsString(path string) (string, error) {
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
}
|