From e97789f7d9c937810c99f556ae1586e16213b744 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Mo=CC=88hrmann?= Date: Fri, 18 Mar 2016 16:56:47 +0100 Subject: [PATCH] fmt: simplify handling of reporting flags to formatters Remove rewriting of flags before calling formatters. Change Flag method to directly take plusV and sharpV flags into account when reporting if plus or sharp flag is set. Change-Id: Ic3423881ad89e5a5f9fff5ab59e842062394ef6d Reviewed-on: https://go-review.googlesource.com/20859 Run-TryBot: Rob Pike TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- src/fmt/print.go | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/fmt/print.go b/src/fmt/print.go index 1cf1246b5d..71f4cabe53 100644 --- a/src/fmt/print.go +++ b/src/fmt/print.go @@ -152,9 +152,9 @@ func (p *pp) Flag(b int) bool { case '-': return p.fmt.minus case '+': - return p.fmt.plus + return p.fmt.plus || p.fmt.plusV case '#': - return p.fmt.sharp + return p.fmt.sharp || p.fmt.sharpV case ' ': return p.fmt.space case '0': @@ -570,34 +570,6 @@ func (p *pp) catchPanic(arg interface{}, verb rune) { } } -// clearSpecialFlags pushes %#v back into the regular flags and returns their old state. -func (p *pp) clearSpecialFlags() (plusV, sharpV bool) { - plusV = p.fmt.plusV - if plusV { - p.fmt.plus = true - p.fmt.plusV = false - } - sharpV = p.fmt.sharpV - if sharpV { - p.fmt.sharp = true - p.fmt.sharpV = false - } - return -} - -// restoreSpecialFlags, whose argument should be a call to clearSpecialFlags, -// restores the setting of the plusV and sharpV flags. -func (p *pp) restoreSpecialFlags(plusV, sharpV bool) { - if plusV { - p.fmt.plus = false - p.fmt.plusV = true - } - if sharpV { - p.fmt.sharp = false - p.fmt.sharpV = true - } -} - func (p *pp) handleMethods(verb rune, depth int) (handled bool) { if p.erroring { return @@ -605,7 +577,6 @@ func (p *pp) handleMethods(verb rune, depth int) (handled bool) { // Is it a Formatter? if formatter, ok := p.arg.(Formatter); ok { handled = true - defer p.restoreSpecialFlags(p.clearSpecialFlags()) defer p.catchPanic(p.arg, verb) formatter.Format(p, verb) return -- 2.48.1