mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
init 1.2.x
This commit is contained in:
59
src/server/utils/strings.go
Normal file
59
src/server/utils/strings.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CleanFName(file string) string {
|
||||
re := regexp.MustCompile(`[ !*'();:@&=+$,/?#\[\]~"{}]`)
|
||||
ret := re.ReplaceAllString(file, `_`)
|
||||
ret = strings.Replace(ret, "__", "_", -1)
|
||||
ret = strings.Replace(ret, "._", "_", -1)
|
||||
ret = strings.Replace(ret, "_.", ".", -1)
|
||||
return ret
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user