mirror of
https://github.com/golang/go
synced 2024-11-21 20:34:40 -07:00
makehtml: use append
The program is old and missed its opportunity. R=gri, adg CC=golang-dev https://golang.org/cl/4178050
This commit is contained in:
parent
7115eef6be
commit
29ae8e9a98
@ -18,13 +18,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lines = make([][]byte, 0, 10000) // assume big enough
|
lines = make([][]byte, 0, 2000) // probably big enough; grows if not
|
||||||
linebuf = make([]byte, 10000) // assume big enough
|
|
||||||
|
|
||||||
empty = []byte("")
|
empty = []byte("")
|
||||||
newline = []byte("\n")
|
newline = []byte("\n")
|
||||||
tab = []byte("\t")
|
tab = []byte("\t")
|
||||||
quote = []byte(`"`)
|
quote = []byte(`"`)
|
||||||
|
indent = []byte{' ', ' ', ' ', ' '}
|
||||||
|
|
||||||
sectionMarker = []byte("----\n")
|
sectionMarker = []byte("----\n")
|
||||||
preStart = []byte("<pre>")
|
preStart = []byte("<pre>")
|
||||||
@ -52,9 +52,7 @@ func read() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
n := len(lines)
|
lines = append(lines, line)
|
||||||
lines = lines[0 : n+1]
|
|
||||||
lines[n] = line
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,19 +171,7 @@ func trim(l []byte) []byte {
|
|||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand tabs to 4 spaces. don't worry about columns.
|
// expand tabs to spaces. don't worry about columns.
|
||||||
func expandTabs(l []byte) []byte {
|
func expandTabs(l []byte) []byte {
|
||||||
j := 0 // position in linebuf.
|
return bytes.Replace(l, tab, indent, -1)
|
||||||
for _, c := range l {
|
|
||||||
if c == '\t' {
|
|
||||||
for k := 0; k < 4; k++ {
|
|
||||||
linebuf[j] = ' '
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
linebuf[j] = c
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return linebuf[0:j]
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user