NJS_TOKEN_ILLEGAL, NJS_TOKEN_ILLEGAL,
NJS_TOKEN_ILLEGAL, NJS_TOKEN_ILLEGAL,
/* \t */ NJS_TOKEN_ILLEGAL, NJS_TOKEN_SPACE,
- /* \n */ NJS_TOKEN_LINE_END, NJS_TOKEN_ILLEGAL,
- /* \r */ NJS_TOKEN_ILLEGAL, NJS_TOKEN_SPACE,
+ /* \n */ NJS_TOKEN_LINE_END, NJS_TOKEN_SPACE,
+ /* \r */ NJS_TOKEN_SPACE, NJS_TOKEN_SPACE,
NJS_TOKEN_ILLEGAL, NJS_TOKEN_ILLEGAL,
/* 0x10 */ NJS_TOKEN_ILLEGAL, NJS_TOKEN_ILLEGAL,
njs_int_t
njs_lexer_make_token(njs_lexer_t *lexer, njs_lexer_token_t *token)
{
- u_char c, *p;
+ u_char c, *p;
+ uint32_t cp;
+ njs_unicode_decode_t ctx;
c = ' ';
+ njs_utf8_decode_init(&ctx);
+
while (lexer->start < lexer->end) {
- c = *lexer->start++;
+ c = *lexer->start;
- if (njs_tokens[c] != NJS_TOKEN_SPACE) {
- break;
+ if (njs_fast_path(!(c & 0x80))) {
+ lexer->start++;
+
+ if (njs_tokens[c] != NJS_TOKEN_SPACE) {
+ break;
+ }
+
+ } else {
+
+ /* Unicode. */
+
+ cp = njs_utf8_decode(&ctx, (const u_char **) &lexer->start,
+ lexer->end);
+ if (njs_slow_path(cp > NJS_UNICODE_MAX_CODEPOINT)) {
+ c = '\0';
+ break;
+ }
+
+ if (!njs_utf8_is_whitespace(cp)) {
+ break;
+ }
}
}
"[a.length, a[33], a[34]]"),
njs_str("35,a,�") },
+ /* Spaces: U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 */
+
+ { njs_str("\x09\x0a\x0b\x0c\x0d \xc2\xa0'a'\xe2\x80\xa8+\xe2\x80\xa9'b'"),
+ njs_str("ab") },
+
/* Escape strings. */
{ njs_str("'\\a \\' \\\" \\\\ \\0 \\b \\f \\n \\r \\t \\v'"),