Commit 4e4eca26 authored by Russ Cox's avatar Russ Cox

fmt: use rune

Lots of internal edits.

Formatter and Scanner interfaces change
(clients to be checked by govet).

R=r
CC=golang-dev
https://golang.org/cl/5305045
parent 28c06182
......@@ -73,7 +73,7 @@ type C struct {
type F int
func (f F) Format(s State, c int) {
func (f F) Format(s State, c rune) {
Fprintf(s, "<%c=F(%d)>", c, int(f))
}
......@@ -546,7 +546,7 @@ func TestCountMallocs(t *testing.T) {
type flagPrinter struct{}
func (*flagPrinter) Format(f State, c int) {
func (*flagPrinter) Format(f State, c rune) {
s := "%"
for i := 0; i < 128; i++ {
if f.Flag(i) {
......@@ -746,7 +746,7 @@ type PanicF struct {
}
// Value receiver.
func (p PanicF) Format(f State, c int) {
func (p PanicF) Format(f State, c rune) {
panic(p.message)
}
......
......@@ -242,8 +242,8 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
}
// If we want a quoted char for %#U, move the data up to make room.
if f.unicode && f.uniQuote && a >= 0 && a <= unicode.MaxRune && unicode.IsPrint(int(a)) {
runeWidth := utf8.RuneLen(int(a))
if f.unicode && f.uniQuote && a >= 0 && a <= unicode.MaxRune && unicode.IsPrint(rune(a)) {
runeWidth := utf8.RuneLen(rune(a))
width := 1 + 1 + runeWidth + 1 // space, quote, rune, quote
copy(buf[i-width:], buf[i:]) // guaranteed to have enough room.
i -= width
......@@ -253,7 +253,7 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
j++
buf[j] = '\''
j++
utf8.EncodeRune(buf[j:], int(a))
utf8.EncodeRune(buf[j:], rune(a))
j += runeWidth
buf[j] = '\''
}
......@@ -400,7 +400,7 @@ func (f *fmt) fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f,
func (f *fmt) fmt_fb32(v float32) { f.padString(strconv.Ftoa32(v, 'b', 0)) }
// fmt_c64 formats a complex64 according to the verb.
func (f *fmt) fmt_c64(v complex64, verb int) {
func (f *fmt) fmt_c64(v complex64, verb rune) {
f.buf.WriteByte('(')
r := real(v)
for i := 0; ; i++ {
......@@ -426,7 +426,7 @@ func (f *fmt) fmt_c64(v complex64, verb int) {
}
// fmt_c128 formats a complex128 according to the verb.
func (f *fmt) fmt_c128(v complex128, verb int) {
func (f *fmt) fmt_c128(v complex128, verb rune) {
f.buf.WriteByte('(')
r := real(v)
for i := 0; ; i++ {
......
......@@ -51,7 +51,7 @@ type State interface {
// The implementation of Format may call Sprintf or Fprintf(f) etc.
// to generate its output.
type Formatter interface {
Format(f State, c int)
Format(f State, c rune)
}
// Stringer is implemented by any value that has a String method,
......@@ -159,7 +159,7 @@ func (p *pp) Flag(b int) bool {
return false
}
func (p *pp) add(c int) {
func (p *pp) add(c rune) {
p.buf.WriteRune(c)
}
......@@ -297,7 +297,7 @@ func (p *pp) unknownType(v interface{}) {
p.buf.WriteByte('?')
}
func (p *pp) badVerb(verb int) {
func (p *pp) badVerb(verb rune) {
p.add('%')
p.add('!')
p.add(verb)
......@@ -317,7 +317,7 @@ func (p *pp) badVerb(verb int) {
p.add(')')
}
func (p *pp) fmtBool(v bool, verb int) {
func (p *pp) fmtBool(v bool, verb rune) {
switch verb {
case 't', 'v':
p.fmt.fmt_boolean(v)
......@@ -328,15 +328,15 @@ func (p *pp) fmtBool(v bool, verb int) {
// fmtC formats a rune for the 'c' format.
func (p *pp) fmtC(c int64) {
rune := int(c) // Check for overflow.
if int64(rune) != c {
rune = utf8.RuneError
r := rune(c) // Check for overflow.
if int64(r) != c {
r = utf8.RuneError
}
w := utf8.EncodeRune(p.runeBuf[0:utf8.UTFMax], rune)
w := utf8.EncodeRune(p.runeBuf[0:utf8.UTFMax], r)
p.fmt.pad(p.runeBuf[0:w])
}
func (p *pp) fmtInt64(v int64, verb int) {
func (p *pp) fmtInt64(v int64, verb rune) {
switch verb {
case 'b':
p.fmt.integer(v, 2, signed, ldigits)
......@@ -394,7 +394,7 @@ func (p *pp) fmtUnicode(v int64) {
p.fmt.sharp = sharp
}
func (p *pp) fmtUint64(v uint64, verb int, goSyntax bool) {
func (p *pp) fmtUint64(v uint64, verb rune, goSyntax bool) {
switch verb {
case 'b':
p.fmt.integer(int64(v), 2, unsigned, ldigits)
......@@ -427,7 +427,7 @@ func (p *pp) fmtUint64(v uint64, verb int, goSyntax bool) {
}
}
func (p *pp) fmtFloat32(v float32, verb int) {
func (p *pp) fmtFloat32(v float32, verb rune) {
switch verb {
case 'b':
p.fmt.fmt_fb32(v)
......@@ -446,7 +446,7 @@ func (p *pp) fmtFloat32(v float32, verb int) {
}
}
func (p *pp) fmtFloat64(v float64, verb int) {
func (p *pp) fmtFloat64(v float64, verb rune) {
switch verb {
case 'b':
p.fmt.fmt_fb64(v)
......@@ -465,7 +465,7 @@ func (p *pp) fmtFloat64(v float64, verb int) {
}
}
func (p *pp) fmtComplex64(v complex64, verb int) {
func (p *pp) fmtComplex64(v complex64, verb rune) {
switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c64(v, verb)
......@@ -476,7 +476,7 @@ func (p *pp) fmtComplex64(v complex64, verb int) {
}
}
func (p *pp) fmtComplex128(v complex128, verb int) {
func (p *pp) fmtComplex128(v complex128, verb rune) {
switch verb {
case 'e', 'E', 'f', 'F', 'g', 'G':
p.fmt.fmt_c128(v, verb)
......@@ -487,7 +487,7 @@ func (p *pp) fmtComplex128(v complex128, verb int) {
}
}
func (p *pp) fmtString(v string, verb int, goSyntax bool) {
func (p *pp) fmtString(v string, verb rune, goSyntax bool) {
switch verb {
case 'v':
if goSyntax {
......@@ -508,7 +508,7 @@ func (p *pp) fmtString(v string, verb int, goSyntax bool) {
}
}
func (p *pp) fmtBytes(v []byte, verb int, goSyntax bool, depth int) {
func (p *pp) fmtBytes(v []byte, verb rune, goSyntax bool, depth int) {
if verb == 'v' || verb == 'd' {
if goSyntax {
p.buf.Write(bytesBytes)
......@@ -547,7 +547,7 @@ func (p *pp) fmtBytes(v []byte, verb int, goSyntax bool, depth int) {
}
}
func (p *pp) fmtPointer(value reflect.Value, verb int, goSyntax bool) {
func (p *pp) fmtPointer(value reflect.Value, verb rune, goSyntax bool) {
var u uintptr
switch value.Kind() {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer:
......@@ -579,7 +579,7 @@ var (
uintptrBits = reflect.TypeOf(uintptr(0)).Bits()
)
func (p *pp) catchPanic(field interface{}, verb int) {
func (p *pp) catchPanic(field interface{}, verb rune) {
if err := recover(); err != nil {
// If it's a nil pointer, just say "<nil>". The likeliest causes are a
// Stringer that fails to guard against nil or a nil pointer for a
......@@ -604,7 +604,7 @@ func (p *pp) catchPanic(field interface{}, verb int) {
}
}
func (p *pp) handleMethods(verb int, plus, goSyntax bool, depth int) (wasString, handled bool) {
func (p *pp) handleMethods(verb rune, plus, goSyntax bool, depth int) (wasString, handled bool) {
// Is it a Formatter?
if formatter, ok := p.field.(Formatter); ok {
handled = true
......@@ -643,7 +643,7 @@ func (p *pp) handleMethods(verb int, plus, goSyntax bool, depth int) (wasString,
return
}
func (p *pp) printField(field interface{}, verb int, plus, goSyntax bool, depth int) (wasString bool) {
func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth int) (wasString bool) {
if field == nil {
if verb == 'T' || verb == 'v' {
p.buf.Write(nilAngleBytes)
......@@ -719,7 +719,7 @@ func (p *pp) printField(field interface{}, verb int, plus, goSyntax bool, depth
}
// printValue is like printField but starts with a reflect value, not an interface{} value.
func (p *pp) printValue(value reflect.Value, verb int, plus, goSyntax bool, depth int) (wasString bool) {
func (p *pp) printValue(value reflect.Value, verb rune, plus, goSyntax bool, depth int) (wasString bool) {
if !value.IsValid() {
if verb == 'T' || verb == 'v' {
p.buf.Write(nilAngleBytes)
......@@ -755,7 +755,7 @@ func (p *pp) printValue(value reflect.Value, verb int, plus, goSyntax bool, dept
// printReflectValue is the fallback for both printField and printValue.
// It uses reflect to print the value.
func (p *pp) printReflectValue(value reflect.Value, verb int, plus, goSyntax bool, depth int) (wasString bool) {
func (p *pp) printReflectValue(value reflect.Value, verb rune, plus, goSyntax bool, depth int) (wasString bool) {
oldValue := p.value
p.value = value
BigSwitch:
......
This diff is collapsed.
......@@ -87,8 +87,8 @@ type FloatTest struct {
// Xs accepts any non-empty run of the verb character
type Xs string
func (x *Xs) Scan(state ScanState, verb int) os.Error {
tok, err := state.Token(true, func(r int) bool { return r == verb })
func (x *Xs) Scan(state ScanState, verb rune) os.Error {
tok, err := state.Token(true, func(r rune) bool { return r == verb })
if err != nil {
return err
}
......@@ -109,7 +109,7 @@ type IntString struct {
s string
}
func (s *IntString) Scan(state ScanState, verb int) os.Error {
func (s *IntString) Scan(state ScanState, verb rune) os.Error {
if _, err := Fscan(state, &s.i); err != nil {
return err
}
......@@ -749,8 +749,8 @@ type TwoLines string
// Attempt to read two lines into the object. Scanln should prevent this
// because it stops at newline; Scan and Scanf should be fine.
func (t *TwoLines) Scan(state ScanState, verb int) os.Error {
chars := make([]int, 0, 100)
func (t *TwoLines) Scan(state ScanState, verb rune) os.Error {
chars := make([]rune, 0, 100)
for nlCount := 0; nlCount < 2; {
c, _, err := state.ReadRune()
if err != nil {
......@@ -812,7 +812,7 @@ type RecursiveInt struct {
next *RecursiveInt
}
func (r *RecursiveInt) Scan(state ScanState, verb int) (err os.Error) {
func (r *RecursiveInt) Scan(state ScanState, verb rune) (err os.Error) {
_, err = Fscan(state, &r.i)
if err != nil {
return
......@@ -838,8 +838,7 @@ func scanInts(r *RecursiveInt, b *bytes.Buffer) (err os.Error) {
if err != nil {
return
}
var c int
c, _, err = b.ReadRune()
c, _, err := b.ReadRune()
if err != nil {
if err == os.EOF {
err = nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment