Parse long unicode

This commit is contained in:
Thomas Pelletier
2015-05-21 18:52:26 -07:00
parent a8327d781a
commit 222e90a7d3
2 changed files with 23 additions and 0 deletions
+17
View File
@@ -395,6 +395,23 @@ func (l *tomlLexer) lexString() tomlLexStateFn {
return l.errorf("invalid unicode escape: \\u" + code)
}
growingString += string(rune(intcode))
case 'U':
l.pos++
code := ""
for i := 0; i < 8; i++ {
c := l.peek()
l.pos++
if !isHexDigit(c) {
return l.errorf("unfinished unicode escape")
}
code = code + string(c)
}
l.pos--
intcode, err := strconv.ParseInt(code, 16, 64)
if err != nil {
return l.errorf("invalid unicode escape: \\U" + code)
}
growingString += string(rune(intcode))
default:
return l.errorf("invalid escape sequence: \\" + string(l.peek()))
}
+6
View File
@@ -458,6 +458,12 @@ func TestKeyEqualStringUnicodeEscape(t *testing.T) {
token{Position{1, 8}, tokenString, "hello ♥"},
token{Position{1, 21}, tokenEOF, ""},
})
testFlow(t, `foo = "hello \U000003B4"`, []token{
token{Position{1, 1}, tokenKey, "foo"},
token{Position{1, 5}, tokenEqual, "="},
token{Position{1, 8}, tokenString, "hello δ"},
token{Position{1, 25}, tokenEOF, ""},
})
}
func TestLiteralString(t *testing.T) {