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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
package main
import (
"fmt"
"bufio"
"os"
"os/exec"
"math"
"strings"
"strconv"
"runtime"
)
func getGitTag() string {
var (
cmdOut []byte
err error
)
cmd := "git"
args := []string{"tag","--points-at","HEAD"}
if cmdOut,err = exec.Command(cmd,args...).Output(); err != nil {
panic(err)
}
return string(cmdOut)
}
//Remove a string from a []string and the int number of strings afterwards
func removeStringFromArray(arr []string,rem string,after int) (out []string) {
found := false
i := 0
for _,st := range arr {
if found {
if i < after {
i++
}else{
found = false
}
}else{
if st == rem {
found = true
}else{
out = append(out,st)
}
}
}
return
}
func isSure(quest string) bool {
fmt.Printf("%s (type 'y/Y/yes' to confirm) : ",quest)
in := bufio.NewReader(os.Stdin)
line, err := in.ReadString('\n')
if(runtime.GOOS == "windows"){
line = strings.TrimSuffix(line, "\r\n") //for Windows
}else{
line = strings.TrimSuffix(line, "\n")
}
checkErr(err)
if ( line == "yes" || line == "y" || line == "Y") {
return true
} else {
return false
}
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func getInput(quest string) string {
fmt.Print(quest)
in := bufio.NewReader(os.Stdin)
line, err := in.ReadString('\n')
if(runtime.GOOS == "windows"){
line = strings.TrimSuffix(line, "\r\n") //for Windows
}else{
line = strings.TrimSuffix(line, "\n")
}
checkErr(err)
return line
}
func getNewInput(quest,old string) string {
if old != "" {
fmt.Println("Current:",old)
}
fmt.Print(quest)
in := bufio.NewReader(os.Stdin)
line, err := in.ReadString('\n')
if(runtime.GOOS == "windows"){
line = strings.TrimSuffix(line, "\r\n") //for Windows
}else{
line = strings.TrimSuffix(line, "\n")
}
checkErr(err)
if line == "" {
return old
}else{
return line
}
}
func stringArray2String(in []string, delim string) (string) {
var out string
for i,a := range in {
if i==0 {
out=a
}else{
out=fmt.Sprintf("%s%s%s",out,delim,a)
}
}
return out
}
func string2FloatArray(in string,delim string)(out []float64) {
read := strings.Split(in,delim)
for _,s := range read{
fs,err := strconv.ParseFloat(s,64)
checkErr(err)
out = append(out,fs)
}
return
}
func string2StringArray(in string,delim string)(out []string) {
read := strings.Split(in,delim)
for _,s := range read{
out = append(out,s)
}
return
}
func RetardRound(x float64) float64 {
t := math.Trunc(x)
if math.Abs(x-t) >= 0.5 {
return t + math.Copysign(1, x)
}
return t
}
func Round(x, unit float64) (float64) {
// return math.Round(x/unit) * unit
return RetardRound(x/unit) * unit
}
func cleanString(in string) (out string) {
work := strings.Replace(in,"/","-",-1)
work = strings.Replace(work,"*","-",-1)
work = strings.Replace(work,":","-",-1)
work = strings.Replace(work,"<","-",-1)
work = strings.Replace(work,">","-",-1)
work = strings.Replace(work,"?","-",-1)
work = strings.Replace(work,"|","-",-1)
work = strings.Replace(work,"+","-",-1)
work = strings.Replace(work,",","-",-1)
work = strings.Replace(work,";","-",-1)
work = strings.Replace(work,"=","-",-1)
work = strings.Replace(work,"[","-",-1)
out = strings.Replace(work,"]","-",-1)
return
}
func sumFloatArray(in []float64) (sum float64) {
for _,e := range in{
sum += e
}
return
}
|