Codebase list golang-github-vbauerster-mpb / f628acb
prefer io.WriteString Vladimir Bauer 8 years ago
1 changed file(s) with 16 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
11
22 import (
33 "fmt"
4 "io"
45 "strconv"
56 "strings"
67 )
3233
3334 type CounterKiB int64
3435
35 func (c CounterKiB) Format(f fmt.State, r rune) {
36 prec, ok := f.Precision()
36 func (c CounterKiB) Format(st fmt.State, r rune) {
37 prec, ok := st.Precision()
3738
3839 if r == 'd' || !ok {
3940 prec = 0
6566 res = strconv.FormatInt(int64(c), 10)
6667 }
6768
68 if f.Flag(int(' ')) {
69 if st.Flag(' ') {
6970 res += " "
7071 }
7172 res += unit
7273
73 if w, ok := f.Width(); ok {
74 if w, ok := st.Width(); ok {
7475 if len(res) < w {
7576 pad := strings.Repeat(" ", w-len(res))
76 if f.Flag(int('-')) {
77 if st.Flag(int('-')) {
7778 res += pad
7879 } else {
7980 res = pad + res
8182 }
8283 }
8384
84 f.Write([]byte(res))
85 io.WriteString(st, res)
8586 }
8687
8788 type CounterKB int64
8889
89 func (c CounterKB) Format(f fmt.State, r rune) {
90 prec, ok := f.Precision()
90 func (c CounterKB) Format(st fmt.State, verb rune) {
91 prec, ok := st.Precision()
9192
92 if r == 'd' || !ok {
93 if verb == 'd' || !ok {
9394 prec = 0
9495 }
95 if r == 'f' && !ok {
96 if verb == 'f' && !ok {
9697 prec = 6
9798 }
9899 // retain old beahavior if s verb used
99 if r == 's' {
100 if verb == 's' {
100101 prec = 1
101102 }
102103
119120 res = strconv.FormatInt(int64(c), 10)
120121 }
121122
122 if f.Flag(int(' ')) {
123 if st.Flag(' ') {
123124 res += " "
124125 }
125126 res += unit
126127
127 if w, ok := f.Width(); ok {
128 if w, ok := st.Width(); ok {
128129 if len(res) < w {
129130 pad := strings.Repeat(" ", w-len(res))
130 if f.Flag(int('-')) {
131 if st.Flag(int('-')) {
131132 res += pad
132133 } else {
133134 res = pad + res
135136 }
136137 }
137138
138 f.Write([]byte(res))
139 io.WriteString(st, res)
139140 }