-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
60 lines (50 loc) · 1.06 KB
/
helper.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
59
60
package wordcounter
import (
"fmt"
"path/filepath"
)
// ToAbsolutePath detects if a path is absolute or not. If not, it converts path to absolute.
func ToAbsolutePath(path string) string {
if path == "" {
return path
}
if !filepath.IsAbs(path) {
absPath, _ := filepath.Abs(path)
path = absPath
}
return path
}
func ConvertToSliceOfString(input [][]interface{}) [][]string {
result := make([][]string, len(input))
for i, row := range input {
result[i] = make([]string, len(row))
for j, value := range row {
if value == nil {
result[i][j] = ""
} else {
result[i][j] = fmt.Sprintf("%v", value)
}
}
}
return result
}
func GetTotal(fcs []*FileCounter) Row {
AllLines := 0
AllChineseChars := 0
AllNonChineseChars := 0
AllTotalChars := 0
for _, fc := range fcs {
AllLines += fc.tc.S.Lines
AllChineseChars += fc.tc.S.ChineseChars
AllNonChineseChars += fc.tc.S.NonChineseChars
AllTotalChars += fc.tc.S.TotalChars
}
row := Row{
"Total",
AllLines,
AllChineseChars,
AllNonChineseChars,
AllTotalChars,
}
return row
}