]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: use rune
authorRuss Cox <rsc@golang.org>
Wed, 26 Oct 2011 05:21:33 +0000 (22:21 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 26 Oct 2011 05:21:33 +0000 (22:21 -0700)
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

src/pkg/fmt/fmt_test.go
src/pkg/fmt/format.go
src/pkg/fmt/print.go
src/pkg/fmt/scan.go
src/pkg/fmt/scan_test.go

index 38280d61f6be3e39951f287dc32101950c1abcda..8a83c9b22a8da3ff6154e37789312eae5a1f37a0 100644 (file)
@@ -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)
 }
 
index 24b15a286b7c5a685321587dd7d2be8258bb2a52..80eb9863353c73e7b793f11d9a8923244eadf229 100644 (file)
@@ -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++ {
index 710baeec1d2cffffe6f6b7329ae06e5d19bba8f7..f80ce7c9274851f2aa418a0e3b17dfaf617a4227 100644 (file)
@@ -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:
index 259451d02f77c443560ed82cb6d5c4dd62b397b3..eae952c9fff895dd0b7420cb33e79d95877b1e54 100644 (file)
@@ -32,7 +32,7 @@ type ScanState interface {
        // If invoked during Scanln, Fscanln, or Sscanln, ReadRune() will
        // return EOF after returning the first '\n' or when reading beyond
        // the specified width.
-       ReadRune() (rune int, size int, err os.Error)
+       ReadRune() (r rune, size int, err os.Error)
        // UnreadRune causes the next call to ReadRune to return the same rune.
        UnreadRune() os.Error
        // SkipSpace skips space in the input. Newlines are treated as space 
@@ -47,7 +47,7 @@ type ScanState interface {
        // EOF.  The returned slice points to shared data that may be overwritten
        // by the next call to Token, a call to a Scan function using the ScanState
        // as input, or when the calling Scan method returns.
-       Token(skipSpace bool, f func(int) bool) (token []byte, err os.Error)
+       Token(skipSpace bool, f func(rune) bool) (token []byte, err os.Error)
        // Width returns the value of the width option and whether it has been set.
        // The unit is Unicode code points.
        Width() (wid int, ok bool)
@@ -62,7 +62,7 @@ type ScanState interface {
 // receiver, which must be a pointer to be useful.  The Scan method is called
 // for any argument to Scan, Scanf, or Scanln that implements it.
 type Scanner interface {
-       Scan(state ScanState, verb int) os.Error
+       Scan(state ScanState, verb rune) os.Error
 }
 
 // Scan scans text read from standard input, storing successive
@@ -149,8 +149,8 @@ const eof = -1
 type ss struct {
        rr       io.RuneReader // where to read input
        buf      bytes.Buffer  // token accumulator
-       peekRune int           // one-rune lookahead
-       prevRune int           // last rune returned by ReadRune
+       peekRune rune          // one-rune lookahead
+       prevRune rune          // last rune returned by ReadRune
        count    int           // runes consumed so far.
        atEOF    bool          // already read EOF
        ssave
@@ -174,12 +174,12 @@ func (s *ss) Read(buf []byte) (n int, err os.Error) {
        return 0, os.NewError("ScanState's Read should not be called. Use ReadRune")
 }
 
-func (s *ss) ReadRune() (rune int, size int, err os.Error) {
+func (s *ss) ReadRune() (r rune, size int, err os.Error) {
        if s.peekRune >= 0 {
                s.count++
-               rune = s.peekRune
-               size = utf8.RuneLen(rune)
-               s.prevRune = rune
+               r = s.peekRune
+               size = utf8.RuneLen(r)
+               s.prevRune = r
                s.peekRune = -1
                return
        }
@@ -188,10 +188,10 @@ func (s *ss) ReadRune() (rune int, size int, err os.Error) {
                return
        }
 
-       rune, size, err = s.rr.ReadRune()
+       r, size, err = s.rr.ReadRune()
        if err == nil {
                s.count++
-               s.prevRune = rune
+               s.prevRune = r
        } else if err == os.EOF {
                s.atEOF = true
        }
@@ -207,8 +207,8 @@ func (s *ss) Width() (wid int, ok bool) {
 
 // The public method returns an error; this private one panics.
 // If getRune reaches EOF, the return value is EOF (-1).
-func (s *ss) getRune() (rune int) {
-       rune, _, err := s.ReadRune()
+func (s *ss) getRune() (r rune) {
+       r, _, err := s.ReadRune()
        if err != nil {
                if err == os.EOF {
                        return eof
@@ -221,9 +221,9 @@ func (s *ss) getRune() (rune int) {
 // mustReadRune turns os.EOF into a panic(io.ErrUnexpectedEOF).
 // It is called in cases such as string scanning where an EOF is a
 // syntax error.
-func (s *ss) mustReadRune() (rune int) {
-       rune = s.getRune()
-       if rune == eof {
+func (s *ss) mustReadRune() (r rune) {
+       r = s.getRune()
+       if r == eof {
                s.error(io.ErrUnexpectedEOF)
        }
        return
@@ -248,7 +248,7 @@ func (s *ss) errorString(err string) {
        panic(scanError{os.NewError(err)})
 }
 
-func (s *ss) Token(skipSpace bool, f func(int) bool) (tok []byte, err os.Error) {
+func (s *ss) Token(skipSpace bool, f func(rune) bool) (tok []byte, err os.Error) {
        defer func() {
                if e := recover(); e != nil {
                        if se, ok := e.(scanError); ok {
@@ -267,7 +267,7 @@ func (s *ss) Token(skipSpace bool, f func(int) bool) (tok []byte, err os.Error)
 }
 
 // notSpace is the default scanning function used in Token.
-func notSpace(r int) bool {
+func notSpace(r rune) bool {
        return !unicode.IsSpace(r)
 }
 
@@ -308,13 +308,13 @@ func (r *readRune) unread(buf []byte) {
 
 // ReadRune returns the next UTF-8 encoded code point from the
 // io.Reader inside r.
-func (r *readRune) ReadRune() (rune int, size int, err os.Error) {
+func (r *readRune) ReadRune() (rr rune, size int, err os.Error) {
        r.buf[0], err = r.readByte()
        if err != nil {
                return 0, 0, err
        }
        if r.buf[0] < utf8.RuneSelf { // fast check for common ASCII case
-               rune = int(r.buf[0])
+               rr = rune(r.buf[0])
                return
        }
        var n int
@@ -328,7 +328,7 @@ func (r *readRune) ReadRune() (rune int, size int, err os.Error) {
                        return
                }
        }
-       rune, size = utf8.DecodeRune(r.buf[0:n])
+       rr, size = utf8.DecodeRune(r.buf[0:n])
        if size < n { // an error
                r.unread(r.buf[size:n])
        }
@@ -387,11 +387,11 @@ func (s *ss) free(old ssave) {
 // skipSpace skips spaces and maybe newlines.
 func (s *ss) skipSpace(stopAtNewline bool) {
        for {
-               rune := s.getRune()
-               if rune == eof {
+               r := s.getRune()
+               if r == eof {
                        return
                }
-               if rune == '\n' {
+               if r == '\n' {
                        if stopAtNewline {
                                break
                        }
@@ -401,7 +401,7 @@ func (s *ss) skipSpace(stopAtNewline bool) {
                        s.errorString("unexpected newline")
                        return
                }
-               if !unicode.IsSpace(rune) {
+               if !unicode.IsSpace(r) {
                        s.UnreadRune()
                        break
                }
@@ -411,21 +411,21 @@ func (s *ss) skipSpace(stopAtNewline bool) {
 // token returns the next space-delimited string from the input.  It
 // skips white space.  For Scanln, it stops at newlines.  For Scan,
 // newlines are treated as spaces.
-func (s *ss) token(skipSpace bool, f func(int) bool) []byte {
+func (s *ss) token(skipSpace bool, f func(rune) bool) []byte {
        if skipSpace {
                s.skipSpace(false)
        }
        // read until white space or newline
        for {
-               rune := s.getRune()
-               if rune == eof {
+               r := s.getRune()
+               if r == eof {
                        break
                }
-               if !f(rune) {
+               if !f(r) {
                        s.UnreadRune()
                        break
                }
-               s.buf.WriteRune(rune)
+               s.buf.WriteRune(r)
        }
        return s.buf.Bytes()
 }
@@ -441,17 +441,17 @@ var boolError = os.NewError("syntax error scanning boolean")
 // consume reads the next rune in the input and reports whether it is in the ok string.
 // If accept is true, it puts the character into the input token.
 func (s *ss) consume(ok string, accept bool) bool {
-       rune := s.getRune()
-       if rune == eof {
+       r := s.getRune()
+       if r == eof {
                return false
        }
-       if strings.IndexRune(ok, rune) >= 0 {
+       if strings.IndexRune(ok, r) >= 0 {
                if accept {
-                       s.buf.WriteRune(rune)
+                       s.buf.WriteRune(r)
                }
                return true
        }
-       if rune != eof && accept {
+       if r != eof && accept {
                s.UnreadRune()
        }
        return false
@@ -459,16 +459,16 @@ func (s *ss) consume(ok string, accept bool) bool {
 
 // peek reports whether the next character is in the ok string, without consuming it.
 func (s *ss) peek(ok string) bool {
-       rune := s.getRune()
-       if rune != eof {
+       r := s.getRune()
+       if r != eof {
                s.UnreadRune()
        }
-       return strings.IndexRune(ok, rune) >= 0
+       return strings.IndexRune(ok, r) >= 0
 }
 
 func (s *ss) notEOF() {
        // Guarantee there is data to be read.
-       if rune := s.getRune(); rune == eof {
+       if r := s.getRune(); r == eof {
                panic(os.EOF)
        }
        s.UnreadRune()
@@ -481,7 +481,7 @@ func (s *ss) accept(ok string) bool {
 }
 
 // okVerb verifies that the verb is present in the list, setting s.err appropriately if not.
-func (s *ss) okVerb(verb int, okVerbs, typ string) bool {
+func (s *ss) okVerb(verb rune, okVerbs, typ string) bool {
        for _, v := range okVerbs {
                if v == verb {
                        return true
@@ -492,7 +492,7 @@ func (s *ss) okVerb(verb int, okVerbs, typ string) bool {
 }
 
 // scanBool returns the value of the boolean represented by the next token.
-func (s *ss) scanBool(verb int) bool {
+func (s *ss) scanBool(verb rune) bool {
        s.skipSpace(false)
        s.notEOF()
        if !s.okVerb(verb, "tv", "boolean") {
@@ -530,7 +530,7 @@ const (
 )
 
 // getBase returns the numeric base represented by the verb and its digit string.
-func (s *ss) getBase(verb int) (base int, digits string) {
+func (s *ss) getBase(verb rune) (base int, digits string) {
        s.okVerb(verb, "bdoUxXv", "integer") // sets s.err
        base = 10
        digits = decimalDigits
@@ -564,13 +564,13 @@ func (s *ss) scanNumber(digits string, haveDigits bool) string {
 // scanRune returns the next rune value in the input.
 func (s *ss) scanRune(bitSize int) int64 {
        s.notEOF()
-       rune := int64(s.getRune())
+       r := int64(s.getRune())
        n := uint(bitSize)
-       x := (rune << (64 - n)) >> (64 - n)
-       if x != rune {
-               s.errorString("overflow on character value " + string(rune))
+       x := (r << (64 - n)) >> (64 - n)
+       if x != r {
+               s.errorString("overflow on character value " + string(r))
        }
-       return rune
+       return r
 }
 
 // scanBasePrefix reports whether the integer begins with a 0 or 0x,
@@ -593,7 +593,7 @@ func (s *ss) scanBasePrefix() (base int, digits string, found bool) {
 
 // scanInt returns the value of the integer represented by the next
 // token, checking for overflow.  Any error is stored in s.err.
-func (s *ss) scanInt(verb int, bitSize int) int64 {
+func (s *ss) scanInt(verb rune, bitSize int) int64 {
        if verb == 'c' {
                return s.scanRune(bitSize)
        }
@@ -626,7 +626,7 @@ func (s *ss) scanInt(verb int, bitSize int) int64 {
 
 // scanUint returns the value of the unsigned integer represented
 // by the next token, checking for overflow.  Any error is stored in s.err.
-func (s *ss) scanUint(verb int, bitSize int) uint64 {
+func (s *ss) scanUint(verb rune, bitSize int) uint64 {
        if verb == 'c' {
                return uint64(s.scanRune(bitSize))
        }
@@ -747,7 +747,7 @@ func (s *ss) convertFloat(str string, n int) float64 {
 // The atof argument is a type-specific reader for the underlying type.
 // If we're reading complex64, atof will parse float32s and convert them
 // to float64's to avoid reproducing this code for each complex type.
-func (s *ss) scanComplex(verb int, n int) complex128 {
+func (s *ss) scanComplex(verb rune, n int) complex128 {
        if !s.okVerb(verb, floatVerbs, "complex") {
                return 0
        }
@@ -761,7 +761,7 @@ func (s *ss) scanComplex(verb int, n int) complex128 {
 
 // convertString returns the string represented by the next input characters.
 // The format of the input is determined by the verb.
-func (s *ss) convertString(verb int) (str string) {
+func (s *ss) convertString(verb rune) (str string) {
        if !s.okVerb(verb, "svqx", "string") {
                return ""
        }
@@ -786,26 +786,26 @@ func (s *ss) quotedString() string {
        case '`':
                // Back-quoted: Anything goes until EOF or back quote.
                for {
-                       rune := s.mustReadRune()
-                       if rune == quote {
+                       r := s.mustReadRune()
+                       if r == quote {
                                break
                        }
-                       s.buf.WriteRune(rune)
+                       s.buf.WriteRune(r)
                }
                return s.buf.String()
        case '"':
                // Double-quoted: Include the quotes and let strconv.Unquote do the backslash escapes.
                s.buf.WriteRune(quote)
                for {
-                       rune := s.mustReadRune()
-                       s.buf.WriteRune(rune)
-                       if rune == '\\' {
+                       r := s.mustReadRune()
+                       s.buf.WriteRune(r)
+                       if r == '\\' {
                                // In a legal backslash escape, no matter how long, only the character
                                // immediately after the escape can itself be a backslash or quote.
                                // Thus we only need to protect the first character after the backslash.
-                               rune := s.mustReadRune()
-                               s.buf.WriteRune(rune)
-                       } else if rune == '"' {
+                               r := s.mustReadRune()
+                               s.buf.WriteRune(r)
+                       } else if r == '"' {
                                break
                        }
                }
@@ -821,7 +821,8 @@ func (s *ss) quotedString() string {
 }
 
 // hexDigit returns the value of the hexadecimal digit
-func (s *ss) hexDigit(digit int) int {
+func (s *ss) hexDigit(d rune) int {
+       digit := int(d)
        switch digit {
        case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
                return digit - '0'
@@ -871,7 +872,7 @@ const floatVerbs = "beEfFgGv"
 const hugeWid = 1 << 30
 
 // scanOne scans a single value, deriving the scanner from the type of the argument.
-func (s *ss) scanOne(verb int, field interface{}) {
+func (s *ss) scanOne(verb rune, field interface{}) {
        s.buf.Reset()
        var err os.Error
        // If the parameter has its own Scan method, use that.
@@ -997,11 +998,11 @@ func (s *ss) doScan(a []interface{}) (numProcessed int, err os.Error) {
        // Check for newline if required.
        if !s.nlIsSpace {
                for {
-                       rune := s.getRune()
-                       if rune == '\n' || rune == eof {
+                       r := s.getRune()
+                       if r == '\n' || r == eof {
                                break
                        }
-                       if !unicode.IsSpace(rune) {
+                       if !unicode.IsSpace(r) {
                                s.errorString("Scan: expected newline")
                                break
                        }
index 3f06e5725cacbabfbcafe690ec527c2ee3d9a3e8..fbc28c1b2bb9886cb832699f34820a4e2b7d053c 100644 (file)
@@ -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