gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

field_format.go (802B)


      1 //go:build kvformat
      2 // +build kvformat
      3 
      4 package kv
      5 
      6 import (
      7 	"codeberg.org/gruf/go-byteutil"
      8 	"codeberg.org/gruf/go-kv/format"
      9 )
     10 
     11 // AppendFormat will append formatted format of Field to 'buf'. See .String() for details.
     12 func (f Field) AppendFormat(buf *byteutil.Buffer, vbose bool) {
     13 	var fmtstr string
     14 	if vbose /* verbose */ {
     15 		fmtstr = "{:?}"
     16 	} else /* regular */ {
     17 		fmtstr = "{:v}"
     18 	}
     19 	AppendQuoteString(buf, f.K)
     20 	buf.WriteByte('=')
     21 	format.Appendf(buf, fmtstr, f.V)
     22 }
     23 
     24 // Value returns the formatted value string of this Field.
     25 func (f Field) Value(vbose bool) string {
     26 	var fmtstr string
     27 	if vbose /* verbose */ {
     28 		fmtstr = "{:?}"
     29 	} else /* regular */ {
     30 		fmtstr = "{:v}"
     31 	}
     32 	buf := byteutil.Buffer{B: make([]byte, 0, bufsize/2)}
     33 	format.Appendf(&buf, fmtstr, f.V)
     34 	return buf.String()
     35 }