From: Petri Lehtinen Date: Thu, 9 Jul 2009 18:48:04 +0000 (+0300) Subject: Make the lexer not depend on locale X-Git-Tag: v1.0~29 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=commitdiff_plain;h=13c7ad32199869836977882f390d896e9cbd1b68 Make the lexer not depend on locale ... by not using isalpha() and isspace(). While at it, fix some other minor things. --- diff --git a/src/load.c b/src/load.c index ca87d3c..c09c4cf 100644 --- a/src/load.c +++ b/src/load.c @@ -88,7 +88,7 @@ static void json_scan_string(json_lex *lex) goto out; } - if(0 <= *p && *p <= 31) { + if(0 <= *p && *p <= 0x1F) { /* control character */ goto out; } @@ -101,8 +101,8 @@ static void json_scan_string(json_lex *lex) goto out; } } - if(*p == '"' || *p == '\\' || *p == '/' || *p == 'b' || - *p == 'f' || *p == 'n' || *p == 'r' || *p == 't') + else if(*p == '"' || *p == '\\' || *p == '/' || *p == 'b' || + *p == 'f' || *p == 'n' || *p == 'r' || *p == 't') p++; else goto out; @@ -231,11 +231,14 @@ static int json_lex_scan(json_lex *lex) lex->value.string = NULL; } - while(isspace(*lex->input)) { - if(*lex->input == '\n') + c = *lex->input; + while(c == ' ' || c == '\t' || c == '\n' || c == '\r') + { + if(c == '\n') lex->line++; lex->input++; + c = *lex->input; } lex->start = lex->input; @@ -245,7 +248,8 @@ static int json_lex_scan(json_lex *lex) lex->token = JSON_TOKEN_EOF; else if(c == '{' || c == '}' || c == '[' || c == ']' || - c == ':' || c == ',') { + c == ':' || c == ',') + { lex->token = c; lex->input++; } @@ -256,11 +260,11 @@ static int json_lex_scan(json_lex *lex) else if(isdigit(c) || c == '-') json_scan_number(lex); - else if(isalpha(c)) { + else if(isupper(c) || islower(c)) { /* eat up the whole identifier for clearer error messages */ int len; - while(isalpha(*lex->input)) + while(isupper(*lex->input) || islower(*lex->input)) lex->input++; len = lex->input - lex->start;