|
Gri |
at Nov 22, 2012 at 1:08 am
|
⇧ |
| |
PTAL.
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.goFile src/pkg/go/fmt/fmt.go (right):
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.go#newcode6src/pkg/go/fmt/fmt.go:6: package fmt
On 2012/11/21 03:42:27, r wrote:
s/surce/source/
also in CL description
this should be package format, not fmt. it will require a renamed
import almost
everywhere it's used.
Done.
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.go#newcode32src/pkg/go/fmt/fmt.go:32: return (&printer.Config{Mode: printerMode,
Tabwidth: tabWidth}).Fprint(dst, fset, node)
On 2012/11/21 03:27:14, bradfitz wrote:
this printer.Config could be a global variable.
Done.
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.go#newcode36src/pkg/go/fmt/fmt.go:36: // an error. src is expected to be a
syntactically correct Go source file.
On 2012/11/21 15:01:39, rog wrote:
It would be more useful if this implemented the same heuristics that
gofmt does
to allow formatting of more kinds of program elements.
Agreed.
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.go#newcode38src/pkg/go/fmt/fmt.go:38: func String(src string) (string, error) {
On 2012/11/21 03:27:14, bradfitz wrote:
Could also make src be of type interface{}, like parser.ParseFile,
which takes
[]byte, string, or io.Reader.
see comment below
https://codereview.appspot.com/6852075/diff/9001/src/pkg/go/fmt/fmt.go#newcode38src/pkg/go/fmt/fmt.go:38: func String(src string) (string, error) {
On 2012/11/21 15:01:39, rog wrote:On 2012/11/21 03:27:14, bradfitz wrote:
Could also make src be of type interface{}, like parser.ParseFile,
which takes
[]byte, string, or io.Reader.
personally I'm not keen on that kind of thing. given that ParseFile
always reads
into a []byte anyway, perhaps just:
func Write(dst io.Writer, source []byte) error
might be good enough to replace both String and Copy here.
the following doesn't seem too much worse than format.String(s)
to me:
var b bytes.Buffer
err := format.Write(&b, []byte(s))
use(b.String())
doesn't seem too much worse than using format.String
to me.
The single entry point makes it obvious what the trade-offs are
too.
Agreed. The interface{} argument for ParseFile was an experiment. It
didn't fail, but it was also not providing an overwhelmingly strong
benefit.
I kept Bytes (as in format.Bytes) but now using io.Writer and a []byte
argument.
I kept String (as in format.String) as a convenience function, and it
turns out, it is actually used in that form already.
https://codereview.appspot.com/6852075/