代码拉取完成,页面将自动刷新
package strs
import (
"math"
"strconv"
"strings"
)
func ParseBytes(s string) uint64 {
s = strings.ReplaceAll(s, " ", "")
n, e := strconv.ParseUint(s, 10, 0)
if e == nil {
return n
}
nums := strings.Split(s, "*")
if len(nums) > 1 {
size := uint64(1)
for _, num := range nums {
n, err := strconv.ParseUint(num, 10, 0)
if err != nil {
return 0
}
size *= n
}
return size
}
ss := strings.ToUpper(s)
bs := []byte(ss)
size := uint64(0)
i := 0
for ; i < len(bs); i++ {
if bs[i] >= '0' && bs[i] <= '9' {
size = size*10 + uint64(bs[i]-'0')
} else {
break
}
}
const KB = 1024
const MB = KB * 1024
const GB = MB * 1024
const TB = GB * 1024
hasB := false
if i < len(bs) {
switch bs[i] {
case 'B':
hasB = true
case 'K':
if size < math.MaxUint64/KB {
size *= KB
}
case 'M':
if size < math.MaxUint64/MB {
size *= MB
}
case 'G':
if size < math.MaxUint64/GB {
size *= GB
}
case 'T':
if size < math.MaxUint64/TB {
size *= TB
}
default:
return 0
}
} else {
return size
}
i++
if i < len(bs) {
//byte
if !hasB {
if bs[i] != 'B' {
return 0
}
i++
if i == len(bs) {
return size
}
}
if i+3 == len(bs) && bs[i] == 'Y' && bs[i+1] == 'T' && bs[i+2] == 'E' {
return size
}
} else {
return size
}
return 0
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。