]> Cypherpunks repositories - gostls13.git/commitdiff
srcextract: HTML-escape output if so desired
authorRobert Griesemer <gri@golang.org>
Wed, 9 Feb 2011 22:08:19 +0000 (14:08 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 9 Feb 2011 22:08:19 +0000 (14:08 -0800)
This functionality was removed with CL 4169041.

Minor simplifications.

R=r, adg
CC=golang-dev
https://golang.org/cl/4171042

doc/codelab/wiki/srcextract.go

index c30a0b760f3484bd175ddea1f8cec81acd6fc04f..67294784e02264bf32f5987df5d7c4b4eb685e7a 100644 (file)
@@ -9,6 +9,7 @@ import (
        "go/token"
        "log"
        "os"
+       "template"
 )
 
 var (
@@ -31,11 +32,6 @@ func main() {
        if err != nil {
                log.Fatal(err)
        }
-       // create printer
-       p := &printer.Config{
-               Mode:     0,
-               Tabwidth: 8,
-       }
        // create filter
        filter := func(name string) bool {
                return name == *getName
@@ -44,8 +40,9 @@ func main() {
        if !ast.FilterFile(file, filter) {
                os.Exit(1)
        }
-       b := new(bytes.Buffer)
-       p.Fprint(b, fs, file)
+       // print the AST
+       var b bytes.Buffer
+       printer.Fprint(&b, fs, file)
        // drop package declaration
        if !*showPkg {
                for {
@@ -67,5 +64,9 @@ func main() {
                }
        }
        // output
-       b.WriteTo(os.Stdout)
+       if *html {
+               template.HTMLEscape(os.Stdout, b.Bytes())
+       } else {
+               b.WriteTo(os.Stdout)
+       }
 }