Commit 232b8b07 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge branch 'ascii' of https://github.com/cremno/mruby into cremno-ascii

parents ccd871bc 71c7d587
...@@ -334,8 +334,7 @@ mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self); ...@@ -334,8 +334,7 @@ mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
/* need to include <ctype.h> to use these macros */ /* need to include <ctype.h> to use these macros */
#ifndef ISPRINT #ifndef ISPRINT
/* #define ISASCII(c) isascii((int)(unsigned char)(c)) */ #define ISASCII(c) (!(((int)(unsigned char)(c)) & ~0x7f))
#define ISASCII(c) 1
#define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c))) #define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c)))
#define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c))) #define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c)))
#define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c))) #define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c)))
......
...@@ -258,7 +258,7 @@ check_keyword(const char *buf, const char *word) ...@@ -258,7 +258,7 @@ check_keyword(const char *buf, const char *word)
size_t len = strlen(word); size_t len = strlen(word);
/* skip preceding spaces */ /* skip preceding spaces */
while (*p && isspace(*p)) { while (*p && isspace((unsigned char)*p)) {
p++; p++;
} }
/* check keyword */ /* check keyword */
...@@ -268,7 +268,7 @@ check_keyword(const char *buf, const char *word) ...@@ -268,7 +268,7 @@ check_keyword(const char *buf, const char *word)
p += len; p += len;
/* skip trailing spaces */ /* skip trailing spaces */
while (*p) { while (*p) {
if (!isspace(*p)) return 0; if (!isspace((unsigned char)*p)) return 0;
p++; p++;
} }
return 1; return 1;
......
...@@ -37,27 +37,6 @@ static char utf8len_codepage_zero[256] = ...@@ -37,27 +37,6 @@ static char utf8len_codepage_zero[256] =
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,
}; };
static const char isspacetable[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
#define ascii_isspace(c) isspacetable[(unsigned char)(c)]
static mrb_int static mrb_int
utf8code(unsigned char* p) utf8code(unsigned char* p)
{ {
...@@ -593,7 +572,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -593,7 +572,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
int ai = mrb_gc_arena_save(mrb); int ai = mrb_gc_arena_save(mrb);
c = (unsigned char)*ptr++; c = (unsigned char)*ptr++;
if (skip) { if (skip) {
if (ascii_isspace(c)) { if (ISSPACE(c)) {
beg = ptr - bptr; beg = ptr - bptr;
} }
else { else {
...@@ -602,7 +581,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -602,7 +581,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
if (lim_p && lim <= i) break; if (lim_p && lim <= i) break;
} }
} }
else if (ascii_isspace(c)) { else if (ISSPACE(c)) {
mrb_ary_push(mrb, result, str_subseq(mrb, str, beg, end-beg)); mrb_ary_push(mrb, result, str_subseq(mrb, str, beg, end-beg));
mrb_gc_arena_restore(mrb, ai); mrb_gc_arena_restore(mrb, ai);
skip = 1; skip = 1;
......
...@@ -42,11 +42,7 @@ static void yywarning(parser_state *p, const char *s); ...@@ -42,11 +42,7 @@ static void yywarning(parser_state *p, const char *s);
static void backref_error(parser_state *p, node *n); static void backref_error(parser_state *p, node *n);
static void tokadd(parser_state *p, int32_t c); static void tokadd(parser_state *p, int32_t c);
#ifndef isascii #define identchar(c) (ISALNUM(c) || (c) == '_' || !ISASCII(c))
#define isascii(c) (((c) & ~0x7f) == 0)
#endif
#define identchar(c) (isalnum(c) || (c) == '_' || !isascii(c))
typedef unsigned int stack_type; typedef unsigned int stack_type;
...@@ -3911,7 +3907,8 @@ parse_string(parser_state *p) ...@@ -3911,7 +3907,8 @@ parse_string(parser_state *p)
return tHD_LITERAL_DELIM; return tHD_LITERAL_DELIM;
} }
} }
} while (ISSPACE(c = nextc(p))); c = nextc(p);
} while (ISSPACE(c));
pushback(p, c); pushback(p, c);
return tLITERAL_DELIM; return tLITERAL_DELIM;
} }
...@@ -4205,14 +4202,14 @@ parser_yylex(parser_state *p) ...@@ -4205,14 +4202,14 @@ parser_yylex(parser_state *p)
static const char end[] = "\n=end"; static const char end[] = "\n=end";
if (peeks(p, begin)) { if (peeks(p, begin)) {
c = peekc_n(p, sizeof(begin)-1); c = peekc_n(p, sizeof(begin)-1);
if (c < 0 || isspace(c)) { if (c < 0 || ISSPACE(c)) {
do { do {
if (!skips(p, end)) { if (!skips(p, end)) {
yyerror(p, "embedded document meets end of file"); yyerror(p, "embedded document meets end of file");
return 0; return 0;
} }
c = nextc(p); c = nextc(p);
} while (!(c < 0 || isspace(c))); } while (!(c < 0 || ISSPACE(c)));
if (c != '\n') skip(p, '\n'); if (c != '\n') skip(p, '\n');
p->lineno++; p->lineno++;
p->column = 0; p->column = 0;
...@@ -4337,7 +4334,7 @@ parser_yylex(parser_state *p) ...@@ -4337,7 +4334,7 @@ parser_yylex(parser_state *p)
yyerror(p, "incomplete character syntax"); yyerror(p, "incomplete character syntax");
return 0; return 0;
} }
if (isspace(c)) { if (ISSPACE(c)) {
if (!IS_ARG()) { if (!IS_ARG()) {
int c2; int c2;
switch (c) { switch (c) {
...@@ -5190,7 +5187,7 @@ parser_yylex(parser_state *p) ...@@ -5190,7 +5187,7 @@ parser_yylex(parser_state *p)
pushback(p, c); pushback(p, c);
} }
} }
if (result == 0 && isupper((int)(unsigned char)tok(p)[0])) { if (result == 0 && ISUPPER(tok(p)[0])) {
result = tCONSTANT; result = tCONSTANT;
} }
else { else {
......
...@@ -1728,27 +1728,6 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) ...@@ -1728,27 +1728,6 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str)
return mrb_nil_value(); return mrb_nil_value();
} }
static const char isspacetable[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
#define ascii_isspace(c) isspacetable[(unsigned char)(c)]
/* 15.2.10.5.35 */ /* 15.2.10.5.35 */
/* /*
...@@ -1844,7 +1823,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -1844,7 +1823,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
int ai = mrb_gc_arena_save(mrb); int ai = mrb_gc_arena_save(mrb);
c = (unsigned char)*ptr++; c = (unsigned char)*ptr++;
if (skip) { if (skip) {
if (ascii_isspace(c)) { if (ISSPACE(c)) {
beg = ptr - bptr; beg = ptr - bptr;
} }
else { else {
...@@ -1853,7 +1832,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) ...@@ -1853,7 +1832,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
if (lim_p && lim <= i) break; if (lim_p && lim <= i) break;
} }
} }
else if (ascii_isspace(c)) { else if (ISSPACE(c)) {
mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg)); mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg));
mrb_gc_arena_restore(mrb, ai); mrb_gc_arena_restore(mrb, ai);
skip = TRUE; skip = TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment