summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-05-29 02:01:03 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-05-29 02:01:03 +0900
commit55fed387a991c984ea2988b733ec42ebccfaaf2a (patch)
tree0dc3a57896a4f88391df9e986542edf5b5ff8f9b
parentb1871cf446a5cde128f8601b5517a8760af67940 (diff)
parent2ee84eb3dfdea45a254d53fbd76576f3bfb57728 (diff)
downloadmruby-55fed387a991c984ea2988b733ec42ebccfaaf2a.tar.gz
mruby-55fed387a991c984ea2988b733ec42ebccfaaf2a.zip
Merge pull request #2806 from cremno/simplify-mruby-ctype-macros
mruby.h: simplify ctype-like macros
-rw-r--r--include/mruby.h27
-rw-r--r--mrbgems/mruby-string-ext/src/string.c1
-rw-r--r--mrbgems/mruby-string-utf8/src/string.c1
-rw-r--r--mrbgems/mruby-struct/src/struct.c1
-rw-r--r--src/class.c1
-rw-r--r--src/dump.c1
-rw-r--r--src/string.c1
-rw-r--r--src/symbol.c1
-rw-r--r--src/variable.c1
9 files changed, 13 insertions, 22 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 48e65fdf8..6eb3af844 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -348,21 +348,20 @@ MRB_API mrb_bool mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass
MRB_API mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
-/* need to include <ctype.h> to use these macros */
#ifndef ISPRINT
-#define ISASCII(c) (!(((int)(unsigned char)(c)) & ~0x7f))
-#define ISPRINT(c) (ISASCII(c) && isprint((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 ISLOWER(c) (ISASCII(c) && islower((int)(unsigned char)(c)))
-#define ISALNUM(c) (ISASCII(c) && isalnum((int)(unsigned char)(c)))
-#define ISALPHA(c) (ISASCII(c) && isalpha((int)(unsigned char)(c)))
-#define ISDIGIT(c) (ISASCII(c) && isdigit((int)(unsigned char)(c)))
-#define ISXDIGIT(c) (ISASCII(c) && isxdigit((int)(unsigned char)(c)))
-#define ISBLANK(c) (ISASCII(c) && ((c) == ' ' || (c) == '\t'))
-#define ISCNTRL(c) (ISASCII(c) && iscntrl((int)(unsigned char)(c)))
-#define TOUPPER(c) (ISASCII(c) ? toupper((int)(unsigned char)(c)) : (c))
-#define TOLOWER(c) (ISASCII(c) ? tolower((int)(unsigned char)(c)) : (c))
+#define ISASCII(c) ((unsigned)(c) <= 0x7f)
+#define ISPRINT(c) (((unsigned)(c) - 0x20) < 0x5f)
+#define ISSPACE(c) ((c) == ' ' || (unsigned)(c) - '\t' < 5)
+#define ISUPPER(c) (((unsigned)(c) - 'A') < 26)
+#define ISLOWER(c) (((unsigned)(c) - 'a') < 26)
+#define ISALPHA(c) ((((unsigned)(c) | 0x20) - 'a') < 26)
+#define ISDIGIT(c) (((unsigned)(c) - '0') < 10)
+#define ISXDIGIT(c) (ISDIGIT(c) || ((unsigned)(c) | 0x20) - 'a' < 6)
+#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
+#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
+#define ISCNTRL(c) ((unsigned)(c) < 0x20 || (c) == 0x7f)
+#define TOUPPER(c) (ISLOWER(c) ? ((c) & 0x5f) : (c))
+#define TOLOWER(c) (ISUPPER(c) ? ((c) | 0x20) : (c))
#endif
MRB_API mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, size_t len);
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c
index 221de5009..e925a82a7 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -1,4 +1,3 @@
-#include <ctype.h>
#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
diff --git a/mrbgems/mruby-string-utf8/src/string.c b/mrbgems/mruby-string-utf8/src/string.c
index ef9457195..e21101df9 100644
--- a/mrbgems/mruby-string-utf8/src/string.c
+++ b/mrbgems/mruby-string-utf8/src/string.c
@@ -5,7 +5,6 @@
#include "mruby/range.h"
#include "mruby/numeric.h"
#include "mruby/re.h"
-#include <ctype.h>
#include <string.h>
static const char utf8len_codepage[256] =
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 28ba9c3db..d2187a2d1 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
diff --git a/src/class.c b/src/class.c
index 7ec6e6944..3246564ec 100644
--- a/src/class.c
+++ b/src/class.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include <stdarg.h>
#include "mruby.h"
#include "mruby/array.h"
diff --git a/src/dump.c b/src/dump.c
index 1ab4c47c5..d9410ec18 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include <string.h>
#include <limits.h>
#include "mruby/dump.h"
diff --git a/src/string.c b/src/string.c
index e05c6f749..128578afd 100644
--- a/src/string.c
+++ b/src/string.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <stddef.h>
diff --git a/src/symbol.c b/src/symbol.c
index 390d69c31..f1c0bf80a 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include <limits.h>
#include <string.h>
#include "mruby.h"
diff --git a/src/variable.c b/src/variable.c
index c4f6fb830..3e451df05 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <ctype.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"