-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.go
More file actions
44 lines (38 loc) · 773 Bytes
/
tools.go
File metadata and controls
44 lines (38 loc) · 773 Bytes
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
package pcircle
import (
"errors"
"fmt"
"strings"
)
func bool2int(b bool) (i int) {
if b {
i = 1
}
return i
}
func bool2int2string(b bool) (s string) {
s = "0"
if b {
s = "1"
}
return s
}
func string2int2bool(s string) (b bool, err error) {
switch s {
case "0":
return false, nil
case "1":
return true, nil
}
return false, errors.New("failed to convert string to int to bool: invalid string " + s)
}
func tokenize(str string) (head, data string) {
sep := strings.IndexRune(str, ':')
return strings.TrimSpace(str[:sep]), strings.TrimSpace(str[sep+1:])
}
func generateLineFor(head string, data interface{}) string {
if ndata, ok := data.(fmt.Stringer); ok {
return head + ": " + ndata.String()
}
return fmt.Sprintf("%v: %v", head, data)
}