/
Utils.go
78 lines (69 loc) · 1.12 KB
/
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
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
package utils
import (
"fmt"
"regexp"
"runtime"
"runtime/debug"
"strconv"
"strings"
)
func CleanFName(file string) string {
re := regexp.MustCompile(`[ !*'();:@&=+$,/?#\[\]~"]`)
ret := re.ReplaceAllString(file, `_`)
ret = strings.Replace(ret, "__", "_", -1)
return ret
}
func FreeOSMem() {
debug.FreeOSMemory()
}
func FreeOSMemGC() {
runtime.GC()
debug.FreeOSMemory()
}
const (
_ = 1.0 << (10 * iota) // ignore first value by assigning to blank identifier
KB
MB
GB
TB
PB
EB
)
func Format(b float64) string {
multiple := ""
value := b
switch {
case b >= EB:
value /= EB
multiple = "EB"
case b >= PB:
value /= PB
multiple = "PB"
case b >= TB:
value /= TB
multiple = "TB"
case b >= GB:
value /= GB
multiple = "GB"
case b >= MB:
value /= MB
multiple = "MB"
case b >= KB:
value /= KB
multiple = "KB"
case b == 0:
return "0"
default:
return strconv.FormatInt(int64(b), 10) + "B"
}
return fmt.Sprintf("%.2f%s", value, multiple)
}
//
//func IsCyrillic(str string) bool {
// for _, r := range str {
// if unicode.Is(unicode.Cyrillic, r) {
// return true
// }
// }
// return false
//}