Codebase list golang-github-vbauerster-mpb / 1bd925a
dry switch unit Vladimir Bauer 6 years ago
3 changed file(s) with 12 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
88 )
99
1010 const (
11 _ib SizeB1024 = iota
11 _ib SizeB1024 = iota + 1
1212 _iKiB SizeB1024 = 1 << (iota * 10)
1313 _iMiB
1414 _iGiB
3232 }
3333 }
3434
35 var b strings.Builder
3635 var unit SizeB1024
3736 switch {
3837 case self < _iKiB:
3938 unit = _ib
40 b.WriteString(strconv.FormatFloat(float64(self), 'f', prec, 64))
4139 case self < _iMiB:
4240 unit = _iKiB
43 b.WriteString(strconv.FormatFloat(float64(self)/float64(_iKiB), 'f', prec, 64))
4441 case self < _iGiB:
4542 unit = _iMiB
46 b.WriteString(strconv.FormatFloat(float64(self)/float64(_iMiB), 'f', prec, 64))
4743 case self < _iTiB:
4844 unit = _iGiB
49 b.WriteString(strconv.FormatFloat(float64(self)/float64(_iGiB), 'f', prec, 64))
5045 case self <= math.MaxInt64:
5146 unit = _iTiB
52 b.WriteString(strconv.FormatFloat(float64(self)/float64(_iTiB), 'f', prec, 64))
5347 }
48
49 var b strings.Builder
50 b.WriteString(strconv.FormatFloat(float64(self)/float64(unit), 'f', prec, 64))
5451
5552 if st.Flag(' ') {
5653 b.WriteString(" ")
7572 }
7673
7774 const (
78 _b SizeB1000 = 0
75 _b SizeB1000 = 1
7976 _KB SizeB1000 = 1000
8077 _MB SizeB1000 = _KB * 1000
8178 _GB SizeB1000 = _MB * 1000
9996 }
10097 }
10198
102 var b strings.Builder
10399 var unit SizeB1000
104100 switch {
105101 case self < _KB:
106102 unit = _b
107 b.WriteString(strconv.FormatFloat(float64(self), 'f', prec, 64))
108103 case self < _MB:
109104 unit = _KB
110 b.WriteString(strconv.FormatFloat(float64(self)/float64(_KB), 'f', prec, 64))
111105 case self < _GB:
112106 unit = _MB
113 b.WriteString(strconv.FormatFloat(float64(self)/float64(_MB), 'f', prec, 64))
114107 case self < _TB:
115108 unit = _GB
116 b.WriteString(strconv.FormatFloat(float64(self)/float64(_GB), 'f', prec, 64))
117109 case self <= math.MaxInt64:
118110 unit = _TB
119 b.WriteString(strconv.FormatFloat(float64(self)/float64(_TB), 'f', prec, 64))
120111 }
112
113 var b strings.Builder
114 b.WriteString(strconv.FormatFloat(float64(self)/float64(unit), 'f', prec, 64))
121115
122116 if st.Flag(' ') {
123117 b.WriteString(" ")
77 // An "invalid array index" compiler error signifies that the constant values have changed.
88 // Re-run the stringer command to generate them again.
99 var x [1]struct{}
10 _ = x[_b-0]
10 _ = x[_b-1]
1111 _ = x[_KB-1000]
1212 _ = x[_MB-1000000]
1313 _ = x[_GB-1000000000]
2424
2525 func (i SizeB1000) String() string {
2626 switch {
27 case i == 0:
27 case i == 1:
2828 return _SizeB1000_name_0
2929 case i == 1000:
3030 return _SizeB1000_name_1
77 // An "invalid array index" compiler error signifies that the constant values have changed.
88 // Re-run the stringer command to generate them again.
99 var x [1]struct{}
10 _ = x[_ib-0]
10 _ = x[_ib-1]
1111 _ = x[_iKiB-1024]
1212 _ = x[_iMiB-1048576]
1313 _ = x[_iGiB-1073741824]
2424
2525 func (i SizeB1024) String() string {
2626 switch {
27 case i == 0:
27 case i == 1:
2828 return _SizeB1024_name_0
2929 case i == 1024:
3030 return _SizeB1024_name_1