diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-01-29 20:52:43 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-01-29 20:52:43 +0000 |
commit | d6f2922e91928b5191a5c5f1b3a6b320712b5ce3 (patch) | |
tree | 4f2fad1f4b778519bdd5941185c7e1d032af055b /libgo/go/fmt | |
parent | 91bfca59095b1cca9d4364996866848eaaf76c26 (diff) | |
download | gcc-d6f2922e91928b5191a5c5f1b3a6b320712b5ce3.zip gcc-d6f2922e91928b5191a5c5f1b3a6b320712b5ce3.tar.gz gcc-d6f2922e91928b5191a5c5f1b3a6b320712b5ce3.tar.bz2 |
libgo: Update Go library to master revision 15489/921e53d4863c.
From-SVN: r195560
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/doc.go | 14 | ||||
-rw-r--r-- | libgo/go/fmt/fmt_test.go | 21 | ||||
-rw-r--r-- | libgo/go/fmt/format.go | 21 | ||||
-rw-r--r-- | libgo/go/fmt/print.go | 18 | ||||
-rw-r--r-- | libgo/go/fmt/scan.go | 9 | ||||
-rw-r--r-- | libgo/go/fmt/scan_test.go | 18 |
6 files changed, 49 insertions, 52 deletions
diff --git a/libgo/go/fmt/doc.go b/libgo/go/fmt/doc.go index ff947b6..2c925a4 100644 --- a/libgo/go/fmt/doc.go +++ b/libgo/go/fmt/doc.go @@ -63,9 +63,10 @@ The default precision for %e and %f is 6; for %g it is the smallest number of digits necessary to identify the value uniquely. - For strings, width is the minimum number of characters to output, - padding with spaces if necessary, and precision is the maximum - number of characters to output, truncating if necessary. + For most values, width is the minimum number of characters to output, + padding the formatted form with spaces if necessary. + For strings, precision is the maximum number of characters to output, + truncating if necessary. Other flags: + always print a sign for numeric values; @@ -77,7 +78,12 @@ write e.g. U+0078 'x' if the character is printable for %U (%#U). ' ' (space) leave a space for elided sign in numbers (% d); put spaces between bytes printing strings or slices in hex (% x, % X) - 0 pad with leading zeros rather than spaces + 0 pad with leading zeros rather than spaces; + for numbers, this moves the padding after the sign + + Flags are ignored by verbs that do not expect them. + For example there is no alternate decimal format, so %#d and %d + behave identically. For each Printf-like function, there is also a Print function that takes no format and is equivalent to saying %v for every diff --git a/libgo/go/fmt/fmt_test.go b/libgo/go/fmt/fmt_test.go index ab06465..dd5e554 100644 --- a/libgo/go/fmt/fmt_test.go +++ b/libgo/go/fmt/fmt_test.go @@ -96,7 +96,7 @@ type SI struct { I interface{} } -// A type with a String method with pointer receiver for testing %p +// P is a type with a String method with pointer receiver for testing %p. type P int var pValue P @@ -676,7 +676,8 @@ func TestStructPrinter(t *testing.T) { } } -// Check map printing using substrings so we don't depend on the print order. +// presentInMap checks map printing using substrings so we don't depend on the +// print order. func presentInMap(s string, a []string, t *testing.T) { for i := 0; i < len(a); i++ { loc := strings.Index(s, a[i]) @@ -717,8 +718,8 @@ func TestEmptyMap(t *testing.T) { } } -// Check that Sprint (and hence Print, Fprint) puts spaces in the right places, -// that is, between arg pairs in which neither is a string. +// TestBlank checks that Sprint (and hence Print, Fprint) puts spaces in the +// right places, that is, between arg pairs in which neither is a string. func TestBlank(t *testing.T) { got := Sprint("<", 1, ">:", 1, 2, 3, "!") expect := "<1>:1 2 3!" @@ -727,8 +728,8 @@ func TestBlank(t *testing.T) { } } -// Check that Sprintln (and hence Println, Fprintln) puts spaces in the right places, -// that is, between all arg pairs. +// TestBlankln checks that Sprintln (and hence Println, Fprintln) puts spaces in +// the right places, that is, between all arg pairs. func TestBlankln(t *testing.T) { got := Sprintln("<", 1, ">:", 1, 2, 3, "!") expect := "< 1 >: 1 2 3 !\n" @@ -737,7 +738,7 @@ func TestBlankln(t *testing.T) { } } -// Check Formatter with Sprint, Sprintln, Sprintf +// TestFormatterPrintln checks Formatter with Sprint, Sprintln, Sprintf. func TestFormatterPrintln(t *testing.T) { f := F(1) expect := "<v=F(1)>\n" @@ -786,7 +787,7 @@ func TestWidthAndPrecision(t *testing.T) { } } -// A type that panics in String. +// Panic is a type that panics in String. type Panic struct { message interface{} } @@ -801,7 +802,7 @@ func (p Panic) String() string { panic(p.message) } -// A type that panics in Format. +// PanicF is a type that panics in Format. type PanicF struct { message interface{} } @@ -839,7 +840,7 @@ func TestPanics(t *testing.T) { } } -// Test that erroneous String routine doesn't cause fatal recursion. +// recurCount tests that erroneous String routine doesn't cause fatal recursion. var recurCount = 0 type Recur struct { diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go index c3d7605..5665db1 100644 --- a/libgo/go/fmt/format.go +++ b/libgo/go/fmt/format.go @@ -72,7 +72,7 @@ func (f *fmt) init(buf *buffer) { f.clearflags() } -// Compute left and right padding widths (only one will be non-zero). +// computePadding computes left and right padding widths (only one will be non-zero). func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth int) { left := !f.minus w := f.wid @@ -95,7 +95,7 @@ func (f *fmt) computePadding(width int) (padding []byte, leftWidth, rightWidth i return } -// Generate n bytes of padding. +// writePadding generates n bytes of padding. func (f *fmt) writePadding(n int, padding []byte) { for n > 0 { m := n @@ -107,8 +107,7 @@ func (f *fmt) writePadding(n int, padding []byte) { } } -// Append b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus) -// clear flags afterwards. +// pad appends b to f.buf, padded on left (w > 0) or right (w < 0 or f.minus). func (f *fmt) pad(b []byte) { if !f.widPresent || f.wid == 0 { f.buf.Write(b) @@ -124,8 +123,7 @@ func (f *fmt) pad(b []byte) { } } -// append s to buf, padded on left (w > 0) or right (w < 0 or f.minus). -// clear flags afterwards. +// padString appends s to buf, padded on left (w > 0) or right (w < 0 or f.minus). func (f *fmt) padString(s string) { if !f.widPresent || f.wid == 0 { f.buf.WriteString(s) @@ -141,17 +139,6 @@ func (f *fmt) padString(s string) { } } -func putint(buf []byte, base, val uint64, digits string) int { - i := len(buf) - 1 - for val >= base { - buf[i] = digits[val%base] - i-- - val /= base - } - buf[i] = digits[val] - return i - 1 -} - var ( trueBytes = []byte("true") falseBytes = []byte("false") diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go index dce46d8..4078f4a 100644 --- a/libgo/go/fmt/print.go +++ b/libgo/go/fmt/print.go @@ -26,8 +26,8 @@ var ( extraBytes = []byte("%!(EXTRA ") irparenBytes = []byte("i)") bytesBytes = []byte("[]byte{") - widthBytes = []byte("%!(BADWIDTH)") - precBytes = []byte("%!(BADPREC)") + badWidthBytes = []byte("%!(BADWIDTH)") + badPrecBytes = []byte("%!(BADPREC)") noVerbBytes = []byte("%!(NOVERB)") ) @@ -153,7 +153,7 @@ func newCache(f func() interface{}) *cache { var ppFree = newCache(func() interface{} { return new(pp) }) -// Allocate a new pp struct or grab a cached one. +// newPrinter allocates a new pp struct or grab a cached one. func newPrinter() *pp { p := ppFree.get().(*pp) p.panicking = false @@ -162,7 +162,7 @@ func newPrinter() *pp { return p } -// Save used pp structs in ppFree; avoids an allocation per invocation. +// free saves used pp structs in ppFree; avoids an allocation per invocation. func (p *pp) free() { // Don't hold on to pp structs with large buffers. if cap(p.buf) > 1024 { @@ -299,7 +299,7 @@ func Sprintln(a ...interface{}) string { return s } -// Get the i'th arg of the struct value. +// getField gets the i'th arg of the struct value. // If the arg itself is an interface, return a value for // the thing inside the interface, not the interface itself. func getField(v reflect.Value, i int) reflect.Value { @@ -310,7 +310,7 @@ func getField(v reflect.Value, i int) reflect.Value { return val } -// Convert ASCII to integer. n is 0 (and got is false) if no number present. +// parsenum converts ASCII to integer. num is 0 (and isnum is false) if no number present. func parsenum(s string, start, end int) (num int, isnum bool, newi int) { if start >= end { return 0, false, end @@ -1057,7 +1057,7 @@ func (p *pp) doPrintf(format string, a []interface{}) { if i < end && format[i] == '*' { p.fmt.wid, p.fmt.widPresent, i, fieldnum = intFromArg(a, end, i, fieldnum) if !p.fmt.widPresent { - p.buf.Write(widthBytes) + p.buf.Write(badWidthBytes) } } else { p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end) @@ -1067,7 +1067,7 @@ func (p *pp) doPrintf(format string, a []interface{}) { if format[i+1] == '*' { p.fmt.prec, p.fmt.precPresent, i, fieldnum = intFromArg(a, end, i+1, fieldnum) if !p.fmt.precPresent { - p.buf.Write(precBytes) + p.buf.Write(badPrecBytes) } } else { p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i+1, end) @@ -1123,7 +1123,7 @@ func (p *pp) doPrint(a []interface{}, addspace, addnewline bool) { prevString := false for fieldnum := 0; fieldnum < len(a); fieldnum++ { p.fmt.clearflags() - // always add spaces if we're doing println + // always add spaces if we're doing Println field := a[fieldnum] if fieldnum > 0 { isString := field != nil && reflect.TypeOf(field).Kind() == reflect.String diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 6a282c8..bf888c4 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -312,8 +312,9 @@ func notSpace(r rune) bool { return !isSpace(r) } -// skipSpace provides Scan() methods the ability to skip space and newline characters -// in keeping with the current scanning mode set by format strings and Scan()/Scanln(). +// SkipSpace provides Scan methods the ability to skip space and newline +// characters in keeping with the current scanning mode set by format strings +// and Scan/Scanln. func (s *ss) SkipSpace() { s.skipSpace(false) } @@ -381,7 +382,7 @@ func (r *readRune) ReadRune() (rr rune, size int, err error) { var ssFree = newCache(func() interface{} { return new(ss) }) -// Allocate a new ss struct or grab a cached one. +// newScanState allocates a new ss struct or grab a cached one. func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) { // If the reader is a *ss, then we've got a recursive // call to Scan, so re-use the scan state. @@ -413,7 +414,7 @@ func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) { return } -// Save used ss structs in ssFree; avoid an allocation per invocation. +// free saves used ss structs in ssFree; avoid an allocation per invocation. func (s *ss) free(old ssave) { // If it was used recursively, just restore the old state. if old.validSave { diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index cc09e91..4e2c0fe 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -626,7 +626,7 @@ func TestScanlnWithMiddleNewline(t *testing.T) { } } -// Special Reader that counts reads at end of file. +// eofCounter is a special Reader that counts reads at end of file. type eofCounter struct { reader *strings.Reader eofCount int @@ -640,8 +640,8 @@ func (ec *eofCounter) Read(b []byte) (n int, err error) { return } -// Verify that when we scan, we see at most EOF once per call to a Scan function, -// and then only when it's really an EOF +// TestEOF verifies that when we scan, we see at most EOF once per call to a +// Scan function, and then only when it's really an EOF. func TestEOF(t *testing.T) { ec := &eofCounter{strings.NewReader("123\n"), 0} var a int @@ -668,7 +668,7 @@ func TestEOF(t *testing.T) { } } -// Verify that we see an EOF error if we run out of input. +// TestEOFAtEndOfInput verifies that we see an EOF error if we run out of input. // This was a buglet: we used to get "expected integer". func TestEOFAtEndOfInput(t *testing.T) { var i, j int @@ -730,7 +730,8 @@ func TestEOFAllTypes(t *testing.T) { } } -// Verify that, at least when using bufio, successive calls to Fscan do not lose runes. +// TestUnreadRuneWithBufio verifies that, at least when using bufio, successive +// calls to Fscan do not lose runes. func TestUnreadRuneWithBufio(t *testing.T) { r := bufio.NewReader(strings.NewReader("123αb")) var i int @@ -753,7 +754,7 @@ func TestUnreadRuneWithBufio(t *testing.T) { type TwoLines string -// Attempt to read two lines into the object. Scanln should prevent this +// Scan attempts 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 rune) error { chars := make([]rune, 0, 100) @@ -820,7 +821,8 @@ func (s *simpleReader) Read(b []byte) (n int, err error) { return s.sr.Read(b) } -// Test that Fscanf does not read past newline. Issue 3481. +// TestLineByLineFscanf tests that Fscanf does not read past newline. Issue +// 3481. func TestLineByLineFscanf(t *testing.T) { r := &simpleReader{strings.NewReader("1\n2\n")} var i, j int @@ -862,7 +864,7 @@ func (r *RecursiveInt) Scan(state ScanState, verb rune) (err error) { return } -// Perform the same scanning task as RecursiveInt.Scan +// scanInts performs the same scanning task as RecursiveInt.Scan // but without recurring through scanner, so we can compare // performance more directly. func scanInts(r *RecursiveInt, b *bytes.Buffer) (err error) { |