本文整理汇总了Golang中fmt.State类的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Format
func (v value) Format(f fmt.State, c rune) {
if debug || f.Flag('#') {
fmt.Fprintf(f, "%s["+v.format+"]", typeName(v.v), v.v)
} else {
fmt.Fprintf(f, v.format, v.v)
}
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:7,代码来源:calc.go
示例2: Format
// Format satisfies the fmt.Formatter interface.
func (f formatter) Format(fs fmt.State, c rune) {
if c == 'v' && fs.Flag('#') {
fmt.Fprintf(fs, "%#v", f.matrix)
return
}
format(f.matrix, f.prefix, f.margin, f.dot, f.squeeze, fs, c)
}
开发者ID:lessc0de,项目名称:matrix,代码行数:8,代码来源:format.go
示例3: Format
// Format is a support routine for fmt.Formatter. It accepts
// the formats 'b' (binary), 'o' (octal), 'd' (decimal), 'x'
// (lowercase hexadecimal), and 'X' (uppercase hexadecimal).
//
func (x *Int) Format(s fmt.State, ch int) {
cs := charset(ch)
// special cases
switch {
case cs == "":
// unknown format
fmt.Fprintf(s, "%%!%c(big.Int=%s)", ch, x.String())
return
case x == nil:
fmt.Fprint(s, "<nil>")
return
}
// determine format
format := "%s"
if s.Flag('#') {
switch ch {
case 'o':
format = "0%s"
case 'x':
format = "0x%s"
case 'X':
format = "0X%s"
}
}
if x.neg {
format = "-" + format
}
fmt.Fprintf(s, format, x.abs.string(cs))
}
开发者ID:go-nosql,项目名称:golang,代码行数:36,代码来源:int.go
示例4: Format
func (fo formatter) Format(f fmt.State, c rune) {
if c == 'v' && f.Flag('#') && f.Flag(' ') {
fo.format(f)
return
}
fo.passThrough(f, c)
}
开发者ID:rjmcguire,项目名称:pretty,代码行数:7,代码来源:formatter.go
示例5: Format
// Format formats the frame according to the fmt.Formatter interface.
//
// %s source file
// %d source line
// %n function name
// %v equivalent to %s:%d
//
// Format accepts flags that alter the printing of some verbs, as follows:
//
// %+s path of source file relative to the compile time GOPATH
// %+v equivalent to %+s:%d
func (f Frame) Format(s fmt.State, verb rune) {
switch verb {
case 's':
switch {
case s.Flag('+'):
pc := f.pc()
fn := runtime.FuncForPC(pc)
if fn == nil {
io.WriteString(s, "unknown")
} else {
file, _ := fn.FileLine(pc)
fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file)
}
default:
io.WriteString(s, path.Base(f.file()))
}
case 'd':
fmt.Fprintf(s, "%d", f.line())
case 'n':
name := runtime.FuncForPC(f.pc()).Name()
io.WriteString(s, funcname(name))
case 'v':
f.Format(s, 's')
io.WriteString(s, ":")
f.Format(s, 'd')
}
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:38,代码来源:stack.go
示例6: Format
func (m fm) Format(fs fmt.State, c rune) {
if c == 'v' && fs.Flag('#') {
fmt.Fprintf(fs, "%#v", m.Matrix)
return
}
Format(m.Matrix, m.margin, '.', fs, c)
}
开发者ID:drewlanenga,项目名称:matrix,代码行数:7,代码来源:format_test.go
示例7: Format
// Format implements fmt.Formatter. It accepts format.State for
// language-specific rendering.
func (v Value) Format(s fmt.State, verb rune) {
var lang int
if state, ok := s.(format.State); ok {
lang, _ = language.CompactIndex(state.Language())
}
// Get the options. Use DefaultFormat if not present.
opt := v.format
if opt == nil {
opt = defaultFormat
}
cur := v.currency
if cur.index == 0 {
cur = opt.currency
}
// TODO: use pattern.
io.WriteString(s, opt.symbol(lang, cur))
if v.amount != nil {
s.Write(space)
// TODO: apply currency-specific rounding
scale, _ := opt.kind.Rounding(cur)
if _, ok := s.Precision(); !ok {
fmt.Fprintf(s, "%.*f", scale, v.amount)
} else {
fmt.Fprint(s, v.amount)
}
}
}
开发者ID:ChongFeng,项目名称:beats,代码行数:32,代码来源:format.go
示例8: Format
// TODO: Implement left/right align
func (b ByteSize) Format(f fmt.State, c rune) {
var decimal bool
switch c {
case 'd':
decimal = true
case 'b':
decimal = false
case 'v':
fmt.Fprintf(f, "%s", b.String())
return
default:
fmt.Fprintf(f, "%%!%c(ByteSize=%s)", c, b.String())
return
}
unit, divisor := b.UnitDivisor(decimal)
fmtstring := "%"
if w, ok := f.Width(); ok {
fmtstring += fmt.Sprintf("%d", w-len(unit)-1)
}
if p, ok := f.Precision(); ok {
fmtstring += fmt.Sprintf(".%d", p)
}
fmtstring += "f %s"
fmt.Fprintf(f, fmtstring, float64(b)/float64(divisor), unit)
}
开发者ID:pwaller,项目名称:go-memhelper,代码行数:29,代码来源:bytesize.go
示例9: writeMultiple
// write count copies of text to s
func writeMultiple(s fmt.State, text string, count int) {
if len(text) > 0 {
b := []byte(text)
for ; count > 0; count-- {
s.Write(b)
}
}
}
开发者ID:Sunmonds,项目名称:gcc,代码行数:9,代码来源:int.go
示例10: Format
func (a Attributes) Format(fs fmt.State, c rune) {
for i, tv := range a {
fmt.Fprintf(fs, "%s %s", tv.Tag, tv.Value)
if i < len(a)-1 {
fs.Write([]byte("; "))
}
}
}
开发者ID:gordon,项目名称:biogo,代码行数:8,代码来源:gff.go
示例11: format
func format(b Bed, fs fmt.State, c rune) {
bv := reflect.ValueOf(b)
if bv.IsNil() {
fmt.Fprint(fs, "<nil>")
return
}
bv = bv.Elem()
switch c {
case 'v':
if fs.Flag('#') {
fmt.Fprintf(fs, "&%#v", bv.Interface())
return
}
fallthrough
case 's':
width, _ := fs.Width()
if !b.canBed(width) {
fmt.Fprintf(fs, "%%!(BADWIDTH)%T", b)
return
}
if width == 0 {
width = bv.NumField()
}
for i := 0; i < width; i++ {
f := bv.Field(i).Interface()
if i >= rgbField {
switch i {
case rgbField:
rv := reflect.ValueOf(f)
if reflect.DeepEqual(rv.Interface(), color.RGBA{}) {
fs.Write([]byte{'0'})
} else {
fmt.Fprintf(fs, "%d,%d,%d",
rv.Field(0).Interface(), rv.Field(1).Interface(), rv.Field(2).Interface())
}
case blockCountField:
fmt.Fprint(fs, f)
case blockSizesField, blockStartsField:
av := reflect.ValueOf(f)
l := av.Len()
for j := 0; j < l; j++ {
fmt.Fprint(fs, av.Index(j).Interface())
if j < l-1 {
fs.Write([]byte{','})
}
}
}
} else {
fmt.Fprint(fs, f)
}
if i < width-1 {
fs.Write([]byte{'\t'})
}
}
default:
fmt.Fprintf(fs, "%%!%c(%T=%3s)", c, b, b)
}
}
开发者ID:gordon,项目名称:biogo,代码行数:58,代码来源:bed.go
示例12: Format
// Format implements the fmt.Formatter interface.
func (v val) Format(s fmt.State, c rune) {
if c == 'v' || c == 's' {
fprint(s, reflect.ValueOf(v.v), state{
defaults: s.Flag('+') || s.Flag('#'),
})
} else {
fmt.Fprintf(s, "%%!%c(pretty.Val)", c)
}
}
开发者ID:trythings,项目名称:trythings,代码行数:10,代码来源:pretty.go
示例13: Format
func (fo formatter) Format(f fmt.State, c rune) {
if fo.force || c == 'v' && f.Flag('#') && f.Flag(' ') {
w := tabwriter.NewWriter(f, 4, 4, 1, ' ', 0)
p := &printer{tw: w, Writer: w, visited: make(map[visit]int)}
p.printValue(reflect.ValueOf(fo.x), true, fo.quote)
w.Flush()
return
}
fo.passThrough(f, c)
}
开发者ID:goodeggs,项目名称:platform,代码行数:10,代码来源:formatter.go
示例14: Format
func (e _error) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v: ", e.Stacktrace()[0])
}
fallthrough
case 's':
io.WriteString(s, e.msg)
}
}
开发者ID:wutaizeng,项目名称:kapacitor,代码行数:11,代码来源:errors.go
示例15: Format
func (s *stack) Format(st fmt.State, verb rune) {
switch verb {
case 'v':
switch {
case st.Flag('+'):
for _, pc := range *s {
f := Frame(pc)
fmt.Fprintf(st, "\n%+v", f)
}
}
}
}
开发者ID:hashicorp,项目名称:consul-replicate,代码行数:12,代码来源:stack.go
示例16: Format
func (f *fundamental) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
io.WriteString(s, f.msg)
f.stack.Format(s, verb)
return
}
fallthrough
case 's', 'q':
io.WriteString(s, f.msg)
}
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:13,代码来源:errors.go
示例17: Format
func (w *withMessage) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v\n", w.Cause())
io.WriteString(s, w.msg)
return
}
fallthrough
case 's', 'q':
io.WriteString(s, w.Error())
}
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:13,代码来源:errors.go
示例18: Format
func (af *ansiFormatter) Format(f fmt.State, c rune) {
// reconstruct the format string in bf
bf := new(bytes.Buffer)
bf.WriteByte('%')
for _, x := range []byte{'-', '+', '#', ' ', '0'} {
if f.Flag(int(x)) {
bf.WriteByte(x)
}
}
if w, ok := f.Width(); ok {
fmt.Fprint(bf, w)
}
if p, ok := f.Precision(); ok {
fmt.Fprintf(bf, ".%d", p)
}
bf.WriteRune(c)
format := bf.String()
if len(af.codes) == 0 {
fmt.Fprintf(f, format, af.value)
return
}
fmt.Fprintf(f, "\x1b[%d", af.codes[0])
for _, code := range af.codes[1:] {
fmt.Fprintf(f, ";%d", code)
}
f.Write([]byte{'m'})
fmt.Fprintf(f, format, af.value)
fmt.Fprint(f, "\x1b[0m")
}
开发者ID:ak-67,项目名称:vuvuzela,代码行数:31,代码来源:ansi.go
示例19: Format
func (r Range) Format(f fmt.State, c int) {
i := byte(0)
for ; i < r.Min; i++ {
f.Write([]byte{'X'})
}
for ; float64(i)+0.5 < r.Mean; i++ {
f.Write([]byte{'x'})
}
for ; i < r.Max; i++ {
f.Write([]byte{'.'})
}
if w, ok := f.Width(); ok {
for ; i < byte(w); i++ {
f.Write([]byte{' '})
}
}
}
开发者ID:droundy,项目名称:abridge,代码行数:17,代码来源:ensemble.go
示例20: formatStruct
func (f *formatter) formatStruct(s fmt.State, c rune, val reflect.Value) {
f.depth++
if f.verbose {
writeType(s, val)
writeLeftcurly(s)
if f.pretty {
writeNewline(s)
writeFullIndent(s, f.depth)
}
} else {
writeLeftcurly(s)
}
typ := val.Type()
for i, n := 0, val.NumField(); i < n; i++ {
field := typ.Field(i)
if i > 0 {
f.sep(s)
}
if f.verbose || f.extra {
s.Write([]byte(field.Name))
writeColon(s)
}
if field.PkgPath == "" {
f.format(s, c, val.Field(i))
} else {
field := typ.Field(i)
var valptr reflect.Value
if val.CanAddr() {
valptr = val.Addr()
} else {
valptr = reflect.New(typ)
reflect.Indirect(valptr).Set(val)
}
fieldp := valptr.Pointer() + field.Offset
fieldptr := reflect.NewAt(field.Type, unsafe.Pointer(fieldp))
f.format(s, c, reflect.Indirect(fieldptr))
}
}
f.depth--
if f.verbose && f.pretty {
writeComma(s)
writeNewline(s)
writeFullIndent(s, f.depth)
}
writeRightcurly(s)
}
开发者ID:bmatsuo,项目名称:go-dfmt,代码行数:46,代码来源:dfmt.go
注:本文中的fmt.State类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论