1
0
mirror of https://github.com/golang/go synced 2024-10-04 16:31:22 -06:00
Commit Graph

105 Commits

Author SHA1 Message Date
Rob Pike
6965b407dd fmt.Scan: custom formatters
R=rsc
CC=golang-dev
https://golang.org/cl/1315042
2010-05-26 18:15:09 -07:00
Rob Pike
5b77928478 fmt: fix 386 build. error strings differ for overflow on 386.
R=gri
CC=golang-dev
https://golang.org/cl/1316042
2010-05-26 10:01:52 -07:00
Rob Pike
71f130f55c fmt.Scan, fmt.Scanln: Start of a simple scanning API in the fmt package.
Still to do:
	- composite types
	- user-defined scanners
	- format-driven scanning
The package comment will be updated when more of the functionality is in place.

R=rsc
CC=golang-dev
https://golang.org/cl/1252045
2010-05-25 21:02:35 -07:00
Robert Griesemer
72fd5c80f8 go/printer, gofmt: fix printing of labels,
apply gofmt to src, misc

Fixes #752.

R=rsc
CC=golang-dev
https://golang.org/cl/1240044
2010-05-21 20:25:08 -07:00
Roger Peppe
14e04f4d40 Prevent Printf crashing when giving an extra nil argument.
R=rsc, r
CC=golang-dev
https://golang.org/cl/1195041
2010-05-13 12:49:48 -07:00
Christopher Wedgwood
1331f8b3cb fmt: %T print <nil> for nil
R=r
CC=golang-dev, rsc
https://golang.org/cl/1014043
2010-04-28 13:07:19 -07:00
Andrei Vieru
1ab15fac22 fmt format verb %b bug
fmt.Printf("%b", int8(-1)) prints 64 ones instead of 8.
This happens only for signed integers (int8, in16 and int32). I guess it's because of the way the conversion between integer types works. From go spec: "Conversions between integer types. If the value is a signed quantity, it is sign extended to implicit infinite precision ....". And there are several conversions to int64 and uint64 in the fmt package. This pathch solves only half of the problem. On a 32 bit system, an fmt.Printf("%b", int(-1)) should still print 64 ones.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/891049
2010-04-12 10:20:06 -07:00
Rob Pike
9280b746ee fmt: enable the complex tests now that 8g supports complex
R=rsc
CC=golang-dev
https://golang.org/cl/357043
2010-03-09 14:17:14 -08:00
Rob Pike
cba81d8058 fix bug in complex printing: imaginary didn't have same format as real.
add tests.

R=rsc, ken2, ken3
CC=golang-dev
https://golang.org/cl/261041
2010-03-06 13:38:14 -08:00
Ken Thompson
788b41751e PTAL
R=r
CC=golang-dev
https://golang.org/cl/254043
2010-03-06 11:26:33 -08:00
Ken Thompson
426099f42e 6g complex type usable
8g and 5g have stubs to ignore complex

R=rsc
CC=golang-dev
https://golang.org/cl/257042
2010-03-05 20:16:04 -08:00
Stephen Ma
a627d61d5d Count utf8 runes, not bytes when determining string width. Note
that pad() still counts bytes, but it's currently only used for
1 byte runes.

Fixes #612.

R=r
CC=golang-dev
https://golang.org/cl/217064
2010-02-28 21:15:56 +11:00
Russ Cox
8fbd5f8a82 use []byte("abc") in place of []byte{'a', 'b', 'c'}
R=gri
CC=golang-dev
https://golang.org/cl/223059
2010-02-25 16:43:43 -08:00
Russ Cox
9750adbbad strings: delete Runes, Bytes
gofmt -w -r 'strings.Bytes(a) -> []byte(a)' src/cmd src/pkg test/bench
gofmt -w -r 'strings.Runes(a) -> []int(a)' src/cmd src/pkg test/bench
delete unused imports

R=r
CC=golang-dev
https://golang.org/cl/224062
2010-02-25 16:01:29 -08:00
Rob Pike
24ee7f799c %q in fmt: if the object is a Stringer, use String() to get the value to quote.
R=rsc
CC=golang-dev
https://golang.org/cl/224051
2010-02-25 17:29:37 +11:00
Ian Lance Taylor
115066fd14 Fix printing of named floating point types.
Try to avoid infinite recursion if String fails due to
printing a bad type.

Add test for String method with named basic types.

R=r
CC=golang-dev
https://golang.org/cl/207102
2010-02-15 22:42:49 -08:00
Rob Pike
2d7dc0e70c handle nils safely in Printf.
add some tests for erroneous formats.

R=rsc
CC=golang-dev
https://golang.org/cl/201058
2010-02-05 11:23:25 +11:00
Russ Cox
33e396a4a7 finalizers; merge package malloc into package runtime
R=r, cw
CC=golang-dev
https://golang.org/cl/198085
2010-02-03 16:31:34 -08:00
Rob Pike
d2fc5d68da Change type of Printf's args to ... interface{}
R=rsc
CC=golang-dev
https://golang.org/cl/197043
2010-02-02 10:53:37 +11:00
Rob Pike
148ee9c009 fix up %p
- use an interface {Get()}
- implement Get for maps, slices
- for slices, retrieves the address of the end of the array, which will give the
	same value for every slice of the same array.

R=rsc
CC=golang-dev
https://golang.org/cl/179129
2009-12-23 07:34:17 +11:00
Rob Pike
2e853ec88a Allow %p on reference types, for debugging.
(Also fix case sensitivity in test for PTR inside fmt_test.go)
Fixes #441.

R=rsc, iant
CC=golang-dev
https://golang.org/cl/180112
2009-12-22 17:02:00 +11:00
Robert Griesemer
1c72959999 1) Change default gofmt default settings for
parsing and printing to new syntax.

                  Use -oldparser to parse the old syntax,
                  use -oldprinter to print the old syntax.

               2) Change default gofmt formatting settings
                  to use tabs for indentation only and to use
                  spaces for alignment. This will make the code
                  alignment insensitive to an editor's tabwidth.

                  Use -spaces=false to use tabs for alignment.

               3) Manually changed src/exp/parser/parser_test.go
                  so that it doesn't try to parse the parser's
                  source files using the old syntax (they have
                  new syntax now).

               4) gofmt -w src misc test/bench

	       2nd set of files.

R=rsc
CC=golang-dev
https://golang.org/cl/179067
2009-12-15 15:27:16 -08:00
Rob Pike
f91cd44736 save a few ns by inlining (which mostly simplifies things anyway).
a couple of cleanups.
don't keep big buffers in the free list.

R=rsc
CC=golang-dev
https://golang.org/cl/166078
2009-12-06 15:01:07 -08:00
Rob Pike
353ef80f65 unexport Fmt. it's not needed outside this package any more
cleans up godoc's output for package fmt substantially.

R=rsc
CC=golang-dev
https://golang.org/cl/165070
2009-12-06 12:58:16 -08:00
Rob Pike
4c0e51cd43 Make printing faster by avoiding mallocs and some other advances.
Roughly 33% faster for simple cases, probably more for complex ones.

Before:

mallocs per Sprintf(""): 4
mallocs per Sprintf("xxx"): 6
mallocs per Sprintf("%x"): 10
mallocs per Sprintf("%x %x"): 12

Now:

mallocs per Sprintf(""): 2
mallocs per Sprintf("xxx"): 3
mallocs per Sprintf("%x"): 5
mallocs per Sprintf("%x %x"): 7

Speed improves because of avoiding mallocs and also by sharing a bytes.Buffer
between print.go and format.go rather than copying the data back after each
printed item.

Before:

fmt_test.BenchmarkSprintfEmpty	1000000	      1346 ns/op
fmt_test.BenchmarkSprintfString	500000	      3461 ns/op
fmt_test.BenchmarkSprintfInt	500000	      3671 ns/op

Now:

fmt_test.BenchmarkSprintfEmpty	 2000000	       995 ns/op
fmt_test.BenchmarkSprintfString	 1000000	      2745 ns/op
fmt_test.BenchmarkSprintfInt	 1000000	      2391 ns/op
fmt_test.BenchmarkSprintfIntInt	  500000	      3751 ns/op

I believe there is more to get but this is a good milestone.

R=rsc
CC=golang-dev, hong
https://golang.org/cl/166076
2009-12-06 12:03:52 -08:00
Rob Pike
d984f98996 minor improvement to formatting: don't allocate padding strings every time.
R=rsc
https://golang.org/cl/164090
2009-12-03 00:04:40 -08:00
Trevor Strohman
f586870ec2 Add benchmarks for commonly used routines.
R=rsc, r, r1
https://golang.org/cl/160046
2009-11-24 00:21:50 -08:00
Sergio Luis O. B. Correia
6fc820729e go: makes it build for the case $GOROOT has whitespaces
the bash scripts and makefiles for building go didn't take into account
the fact $GOROOT / $GOBIN could both be directories containing whitespaces,
and was not possible to build it in such a situation.

this commit adjusts the various makefiles/scripts to make it aware of that
possibility, and now it builds successfully when using a path with whitespaces
as well.

Fixes #115.

R=rsc, dsymonds1
https://golang.org/cl/157067
2009-11-23 17:32:51 -08:00
Russ Cox
9ac4449cb2 gofmt -r 'α[β:len(α)] -> α[β:]' -w src/cmd src/pkg
R=r, gri
CC=golang-dev
https://golang.org/cl/156115
2009-11-20 11:45:05 -08:00
Rob Pike
542e5b8ade add unimplemented %+ and % (space) flags to floating-point print.
fix %E: was same as %e.
add tests.

Fixes #278.

R=rsc
CC=golang-dev
https://golang.org/cl/157111
2009-11-20 11:04:51 -08:00
Rob Pike
ea5cc6c021 add a test for %+v in nested structures.
threw in an embedded one for good measure.

R=rsc
CC=golang-dev
https://golang.org/cl/157058
2009-11-17 22:14:34 -08:00
Robert Griesemer
baba292998 - replaced gofmt expression formatting algorithm with
rsc's algorithm
	- applied gofmt -w misc src
	- partial CL (remaining files in other CLs)

R=rsc, r
http://go/go-review/1026036
2009-11-09 21:13:17 -08:00
Robert Griesemer
40621d5c0d remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
2009-11-09 12:07:39 -08:00
Robert Griesemer
368f8cbc75 - fine-tuning of one-line func heuristic (nodes.go)
- enabled for function declarations (not just function literals)
- applied gofmt -w $GOROOT/src
(look for instance at src/pkg/debug/elf/elf.go)

R=r, rsc
CC=go-dev
http://go/go-review/1026006
2009-11-06 14:24:38 -08:00
Robert Griesemer
30c7088c95 gofmt-ify template, time, unsafe, flag, fmt
(replacement for CLs 1017039, 1017041, 1017040, 1018054)

R=r
http://go/go-review/1018060
2009-11-05 09:40:28 -08:00
Russ Cox
094f1d5990 more lgtm files from gofmt
R=gri
OCL=35485
CL=35488
2009-10-08 15:14:54 -07:00
Russ Cox
ecb863a9a9 apply gofmt to datafmt, ebnf, exec, expvar, flag, fmt
R=gri
DELTA=456  (6 added, 3 deleted, 447 changed)
OCL=35398
CL=35406
2009-10-06 15:38:57 -07:00
Russ Cox
20011bc878 unused imports
R=r
OCL=34731
CL=34731
2009-09-17 10:27:04 -07:00
Russ Cox
ca6a0fee1b more "declared and not used".
the last round omitted := range and only
checked 1 out of N vars in a multi-var :=

R=r
OCL=34624
CL=34638
2009-09-15 09:41:59 -07:00
Russ Cox
8f2bf201d3 fix indentation
R=r
DELTA=166  (0 added, 0 deleted, 166 changed)
OCL=34521
CL=34527
2009-09-10 14:18:53 -07:00
Russ Cox
a843b4541a fmt: add verbs:
%E - upper case %e
	%G - upper case %g
	%#v - Go syntax

R=r
DELTA=332  (238 added, 47 deleted, 47 changed)
OCL=34091
CL=34145
2009-08-31 16:38:30 -07:00
Rob Pike
c6540d31f6 print the value using (in effect) %v when Printf is given mismatched args for its format
Printf("%s", 2) gives %s(int=2)

R=rsc
DELTA=12  (10 added, 0 deleted, 2 changed)
OCL=34042
CL=34044
2009-08-28 13:02:34 -07:00
Russ Cox
3b864e4195 convert low-level (used by testing) packages to
whole-package compilation.  new Makefiles,
tests now in separate package

	bytes
	flag
	fmt
	io
	math
	once
	os
	reflect
	strconv
	sync
	time
	utf8

delete import "xxx" in package xxx.

inside package xxx, xxx is not declared
anymore so s/xxx.//g

delete file and package level forward declarations.

note the new internal_test.go and sync
and strconv to provide public access to
internals during testing.  the installed version
of the package omits that file and thus does
not open the internals to all clients.

R=r
OCL=33065
CL=33097
2009-08-12 13:18:37 -07:00
Russ Cox
0496040bd6 remove unnecessary pkg. references
R=r
DELTA=95  (0 added, 0 deleted, 95 changed)
OCL=33012
CL=33012
2009-08-10 22:02:51 -07:00
Rob Pike
cb9c973829 don't crash printing a nil map
R=rsc
DELTA=19  (18 added, 0 deleted, 1 changed)
OCL=32656
CL=32670
2009-08-03 13:34:20 -07:00
Rob Pike
318b67cb73 make %v and %p consistent
R=rsc
DELTA=1  (0 added, 0 deleted, 1 changed)
OCL=32591
CL=32593
2009-07-31 12:42:21 -07:00
Rob Pike
07a497fee0 fix a long-standing typo
R=rsc
DELTA=2  (0 added, 0 deleted, 2 changed)
OCL=32540
CL=32545
2009-07-30 16:57:46 -07:00
Russ Cox
92e925778e reflection for interface set
rename map access methods to Elem, SetElem.

R=r
DELTA=95  (66 added, 7 deleted, 22 changed)
OCL=31456
CL=31469
2009-07-10 16:32:26 -07:00
Rob Pike
3928a4e11b printing maps
R=rsc
DELTA=57  (39 added, 3 deleted, 15 changed)
OCL=31424
CL=31430
2009-07-09 17:30:07 -07:00
Russ Cox
0d400a7dea fmt: use new reflect interface (CL 31107)
R=r
DELTA=208  (37 added, 63 deleted, 108 changed)
OCL=31111
CL=31281
2009-07-07 11:03:31 -07:00
Russ Cox
d3a412a5ab io.StringBytes -> strings.Bytes
io.ByteBuffer -> bytes.Buffer

left io.ByteBuffer stub around for now,
for protocol compiler.

R=r
OCL=30861
CL=30872
2009-06-29 15:24:23 -07:00
Rob Pike
28ba9777e6 rename Formatter to State and Format to Formatter, for nomenclatural consistency
R=rsc
DELTA=9  (0 added, 0 deleted, 9 changed)
OCL=30658
CL=30658
2009-06-23 15:20:30 -07:00
Rob Pike
b6ce2a72e1 document the verbs for Printf
R=rsc
DELTA=61  (48 added, 0 deleted, 13 changed)
OCL=30616
CL=30619
2009-06-22 18:09:40 -07:00
Russ Cox
da5abb9fb3 changes required if we disallow the implicit *
in cap, len, [], and range on maps, strings, and slices.

R=r
DELTA=57  (2 added, 12 deleted, 43 changed)
OCL=30549
CL=30590
2009-06-22 13:34:21 -07:00
Rob Pike
d90e7cbac6 mv src/lib to src/pkg
tests: all.bash passes, gobuild still works, godoc still works.

R=rsc
OCL=30096
CL=30102
2009-06-09 09:53:44 -07:00