-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
58 lines (48 loc) · 801 Bytes
/
util.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 eyego
import (
"io"
"bufio"
"strconv"
"os"
"strings"
)
func EachLine(r io.Reader, f func(string) interface {}) (rv []interface {}, err error){
br := bufio.NewReader(r)
rv = make([]interface {}, 10)
for {
line, err := br.ReadString('\n')
if line != "" {
rv = append(rv, f(line[:len(line) - 1]))
}
if err != nil {
break
}
}
return rv, err
}
func Atoi(s string) (i int) {
i, err := strconv.Atoi(strings.Trim(s, "\x00"));
if err != nil {
panic(err)
}
return
}
func Abs(i int) int {
if i < 0 {
return -i
}
return i
}
func CopyFile(dst, src string) (int64, error) {
sf, err := os.Open(src)
if err != nil {
return 0, err
}
defer sf.Close()
df, err := os.Create(dst)
if err != nil {
return 0, err
}
defer df.Close()
return io.Copy(df, sf)
}