diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 15:23:52 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-31 15:23:52 +0000 |
commit | b9702967ee6ce84303296b111f596fefab3a60a9 (patch) | |
tree | 1d06e8295c2545767c9506ed39fd1c6ac8829167 /libgo/go/fmt | |
parent | 67376cd2a504c8357d4433f8262b819a8f5af0d9 (diff) | |
download | gcc-b9702967ee6ce84303296b111f596fefab3a60a9.zip gcc-b9702967ee6ce84303296b111f596fefab3a60a9.tar.gz gcc-b9702967ee6ce84303296b111f596fefab3a60a9.tar.bz2 |
libgo: Update from Go 1.5 to Go 1.5.1.
Reviewed-on: https://go-review.googlesource.com/16527
From-SVN: r229624
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/scan.go | 13 | ||||
-rw-r--r-- | libgo/go/fmt/scan_test.go | 11 |
2 files changed, 16 insertions, 8 deletions
diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 5b9b516..e3e0fd0 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -83,6 +83,8 @@ func Scanln(a ...interface{}) (n int, err error) { // the format. It returns the number of items successfully scanned. // If that is less than the number of arguments, err will report why. // Newlines in the input must match newlines in the format. +// The one exception: the verb %c always scans the next rune in the +// input, even if it is a space (or tab etc.) or newline. func Scanf(format string, a ...interface{}) (n int, err error) { return Fscanf(os.Stdin, format, a...) } @@ -1164,15 +1166,18 @@ func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err erro if !widPresent { s.maxWid = hugeWid } - s.SkipSpace() + + c, w := utf8.DecodeRuneInString(format[i:]) + i += w + + if c != 'c' { + s.SkipSpace() + } s.argLimit = s.limit if f := s.count + s.maxWid; f < s.argLimit { s.argLimit = f } - c, w := utf8.DecodeRuneInString(format[i:]) - i += w - if numProcessed >= len(a) { // out of operands s.errorString("too few operands for format %" + format[i-w:]) break diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index a378436..334c4a6 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -300,10 +300,13 @@ var scanfTests = []ScanfTest{ {"%2s", "sssss", &xVal, Xs("ss")}, // Fixed bugs - {"%d\n", "27\n", &intVal, 27}, // ok - {"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline" - {"%v", "0", &intVal, 0}, // was: "EOF"; 0 was taken as base prefix and not counted. - {"%v", "0", &uintVal, uint(0)}, // was: "EOF"; 0 was taken as base prefix and not counted. + {"%d\n", "27\n", &intVal, 27}, // ok + {"%d\n", "28 \n", &intVal, 28}, // was: "unexpected newline" + {"%v", "0", &intVal, 0}, // was: "EOF"; 0 was taken as base prefix and not counted. + {"%v", "0", &uintVal, uint(0)}, // was: "EOF"; 0 was taken as base prefix and not counted. + {"%c", " ", &uintVal, uint(' ')}, // %c must accept a blank. + {"%c", "\t", &uintVal, uint('\t')}, // %c must accept any space. + {"%c", "\n", &uintVal, uint('\n')}, // %c must accept any space. } var overflowTests = []ScanTest{ |