-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
utils.go
49 lines (42 loc) · 856 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
package errlog
import "strings"
func isIntInSlice(i int, s []int) bool {
for vi := range s {
if s[vi] == i {
return true
}
}
return false
}
//deleteBlankLinesFromRange increments and decrements respectively start and end so they are not representing an empty line (in slice lines)
func deleteBlankLinesFromRange(lines []string, start, end *int) {
//clean from out of range values
(*start) = max(*start, 0)
(*end) = min(*end, len(lines)-1)
//clean leading blank lines
for (*start) <= (*end) {
if strings.Trim(lines[(*start)], " \n\t") != "" {
break
}
(*start)++
}
//clean trailing blank lines
for (*end) >= (*start) {
if strings.Trim(lines[(*end)], " \n\t") != "" {
break
}
(*end)--
}
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}