constructOrigFormat recreates the original format string including precision and width information to pass along to the standard fmt package. This allows automatic deferral of all format strings this package doesn't support.
(verb rune)
| 63 | // and width information to pass along to the standard fmt package. This allows |
| 64 | // automatic deferral of all format strings this package doesn't support. |
| 65 | func (f *formatState) constructOrigFormat(verb rune) (format string) { |
| 66 | buf := bytes.NewBuffer(percentBytes) |
| 67 | |
| 68 | for _, flag := range supportedFlags { |
| 69 | if f.fs.Flag(int(flag)) { |
| 70 | buf.WriteRune(flag) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if width, ok := f.fs.Width(); ok { |
| 75 | buf.WriteString(strconv.Itoa(width)) |
| 76 | } |
| 77 | |
| 78 | if precision, ok := f.fs.Precision(); ok { |
| 79 | buf.Write(precisionBytes) |
| 80 | buf.WriteString(strconv.Itoa(precision)) |
| 81 | } |
| 82 | |
| 83 | buf.WriteRune(verb) |
| 84 | |
| 85 | format = buf.String() |
| 86 | return format |
| 87 | } |
| 88 | |
| 89 | // unpackValue returns values inside of non-nil interfaces when possible and |
| 90 | // ensures that types for values which have been unpacked from an interface |