mirror of
https://github.com/golang/go
synced 2024-11-19 16:24:45 -07:00
exp/template: simpler parse of char constants.
We can avoid the check against empty constants (''), which UnquoteChar doesn't handle well, by leaving on the trailing quote and seeing that's all we have left at the end. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4657090
This commit is contained in:
parent
bf9531f80b
commit
0027dc91b0
@ -293,15 +293,12 @@ func newNumber(text string, typ itemType) (*numberNode, os.Error) {
|
|||||||
n := &numberNode{nodeType: nodeNumber, text: text}
|
n := &numberNode{nodeType: nodeNumber, text: text}
|
||||||
switch typ {
|
switch typ {
|
||||||
case itemChar:
|
case itemChar:
|
||||||
if len(text) < 3 {
|
rune, _, tail, err := strconv.UnquoteChar(text[1:], text[0])
|
||||||
return nil, fmt.Errorf("illegal character constant: %s", text)
|
|
||||||
}
|
|
||||||
rune, _, tail, err := strconv.UnquoteChar(text[1:len(text)-1], text[0])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(tail) > 0 {
|
if tail != "'" {
|
||||||
return nil, fmt.Errorf("extra bytes in character constant: %s", text)
|
return nil, fmt.Errorf("malformed character constant: %s", text)
|
||||||
}
|
}
|
||||||
n.int64 = int64(rune)
|
n.int64 = int64(rune)
|
||||||
n.isInt = true
|
n.isInt = true
|
||||||
|
Loading…
Reference in New Issue
Block a user