mirror of
https://github.com/golang/go
synced 2024-11-25 06:57:58 -07:00
template: cosmetic cleanups.
Remove the idea of space being white. Sometimes space is green. Simplify a comment and remove the Latin. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4532096
This commit is contained in:
parent
e11d94fcd7
commit
62943df829
@ -236,8 +236,8 @@ func isExported(name string) bool {
|
|||||||
|
|
||||||
// -- Lexical analysis
|
// -- Lexical analysis
|
||||||
|
|
||||||
// Is c a white space character?
|
// Is c a space character?
|
||||||
func white(c uint8) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' }
|
func isSpace(c uint8) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' }
|
||||||
|
|
||||||
// Safely, does s[n:n+len(t)] == t?
|
// Safely, does s[n:n+len(t)] == t?
|
||||||
func equal(s []byte, n int, t []byte) bool {
|
func equal(s []byte, n int, t []byte) bool {
|
||||||
@ -292,9 +292,9 @@ func (t *Template) nextItem() []byte {
|
|||||||
t.linenum++
|
t.linenum++
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
// Leading white space up to but not including newline
|
// Leading space up to but not including newline
|
||||||
for i = start; i < len(t.buf); i++ {
|
for i = start; i < len(t.buf); i++ {
|
||||||
if t.buf[i] == '\n' || !white(t.buf[i]) {
|
if t.buf[i] == '\n' || !isSpace(t.buf[i]) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ func (t *Template) nextItem() []byte {
|
|||||||
firstChar := t.buf[left+len(t.ldelim)]
|
firstChar := t.buf[left+len(t.ldelim)]
|
||||||
if firstChar == '.' || firstChar == '#' {
|
if firstChar == '.' || firstChar == '#' {
|
||||||
// It's special and the first thing on the line. Is it the last?
|
// It's special and the first thing on the line. Is it the last?
|
||||||
for j := right; j < len(t.buf) && white(t.buf[j]); j++ {
|
for j := right; j < len(t.buf) && isSpace(t.buf[j]); j++ {
|
||||||
if t.buf[j] == '\n' {
|
if t.buf[j] == '\n' {
|
||||||
// Yes it is. Drop the surrounding space and return the {.foo}
|
// Yes it is. Drop the surrounding space and return the {.foo}
|
||||||
t.linenum++
|
t.linenum++
|
||||||
@ -351,7 +351,7 @@ func (t *Template) nextItem() []byte {
|
|||||||
}
|
}
|
||||||
// No it's not. If there's leading space, return that.
|
// No it's not. If there's leading space, return that.
|
||||||
if leadingSpace {
|
if leadingSpace {
|
||||||
// not trimming space: return leading white space if there is some.
|
// not trimming space: return leading space if there is some.
|
||||||
t.p = left
|
t.p = left
|
||||||
return t.buf[start:left]
|
return t.buf[start:left]
|
||||||
}
|
}
|
||||||
@ -374,13 +374,13 @@ func (t *Template) nextItem() []byte {
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn a byte array into a white-space-split array of strings,
|
// Turn a byte array into a space-split array of strings,
|
||||||
// taking into account quoted strings.
|
// taking into account quoted strings.
|
||||||
func words(buf []byte) []string {
|
func words(buf []byte) []string {
|
||||||
s := make([]string, 0, 5)
|
s := make([]string, 0, 5)
|
||||||
for i := 0; i < len(buf); {
|
for i := 0; i < len(buf); {
|
||||||
// One word per loop
|
// One word per loop
|
||||||
for i < len(buf) && white(buf[i]) {
|
for i < len(buf) && isSpace(buf[i]) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
if i == len(buf) {
|
if i == len(buf) {
|
||||||
@ -396,9 +396,9 @@ func words(buf []byte) []string {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Even with quotes, break on whitespace only. This will
|
// Even with quotes, break on space only. This handles input
|
||||||
// work with e.g. {""|} and catch quoting mistakes properly.
|
// such as {""|} and catches quoting mistakes.
|
||||||
for i < len(buf) && !white(buf[i]) {
|
for i < len(buf) && !isSpace(buf[i]) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
s = append(s, string(buf[start:i]))
|
s = append(s, string(buf[start:i]))
|
||||||
@ -1013,13 +1013,13 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A valid delimiter must contain no white space and be non-empty.
|
// A valid delimiter must contain no space and be non-empty.
|
||||||
func validDelim(d []byte) bool {
|
func validDelim(d []byte) bool {
|
||||||
if len(d) == 0 {
|
if len(d) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, c := range d {
|
for _, c := range d {
|
||||||
if white(c) {
|
if isSpace(c) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user