github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/efmt/efmt_api.go (about) 1 package efmt 2 3 import "reflect" 4 5 const ( 6 ldigits = "0123456789abcdefx" 7 udigits = "0123456789ABCDEFX" 8 ) 9 10 const ( 11 signed = true 12 unsigned = false 13 ) 14 15 const ( 16 commaSpaceString = ", " 17 nilAngleString = "<nil>" 18 nilParenString = "(nil)" 19 nilString = "nil" 20 mapString = "map[" 21 percentBangString = "%!" 22 missingString = "(MISSING)" 23 badIndexString = "(BADINDEX)" 24 panicString = "(PANIC=" 25 extraString = "%!(EXTRA " 26 badWidthString = "%!(BADWIDTH)" 27 badPrecString = "%!(BADPREC)" 28 noVerbString = "%!(NOVERB)" 29 invReflectString = "<invalid reflect.Value>" 30 ) 31 32 type Printer struct { 33 pp 34 } 35 36 // Sprintf formats according to a format specifier and returns the result as []byte. 37 func (t *Printer) Sprintf(format string, a ...interface{}) []byte { 38 t.reset() 39 t.doPrintf(format, a) 40 return t.buf 41 } 42 43 // Sprint formats using the default formats for its operands and returns the result as []byte. 44 // Spaces are added between operands when neither is a string. 45 func (t *Printer) Sprint(a ...interface{}) []byte { 46 t.reset() 47 t.doPrint(a) 48 return t.buf 49 } 50 51 func (p *pp) reset() { 52 p.buf = p.buf[:0] 53 p.arg = nil 54 p.value = reflect.Value{} 55 p.panicking = false 56 p.erroring = false 57 p.wrapErrs = false 58 p.wrappedErr = nil 59 60 p.fmt.init(&p.buf) 61 }