-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
58 lines (49 loc) · 969 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ggtfs
import (
"encoding/csv"
"io"
"strings"
)
func ReadHeaderRow(r *csv.Reader) (map[string]uint8, error) {
row, err := r.Read()
if err == io.EOF {
return nil, nil
}
if err != nil {
return nil, err
}
var headers = map[string]uint8{}
for index, item := range row {
headers[strings.TrimSpace(item)] = uint8(index)
}
return headers, nil
}
func ReadDataRow(r *csv.Reader) ([]string, error) {
row, err := r.Read()
if err == io.EOF {
return nil, nil
}
if err != nil {
return nil, err
}
var trimmedRow []string
for _, item := range row {
trimmedRow = append(trimmedRow, strings.TrimSpace(item))
}
return trimmedRow, nil
}
func StringArrayContainsItem(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func tableToString(rows [][]string) string {
var sb strings.Builder
for _, row := range rows {
sb.WriteString(strings.Join(row, ",") + "\n")
}
return sb.String()
}