summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorcremno <[email protected]>2015-05-28 10:20:41 +0200
committercremno <[email protected]>2015-05-28 10:20:41 +0200
commit85075bef7583edd0a48cfbdfaa632cbdacf78f2c (patch)
tree9a75344759811409f44f5476aed29d763846958e /include
parentcd4cc3bd9d9f7fb5a752970b769523cfec7842e5 (diff)
downloadmruby-85075bef7583edd0a48cfbdfaa632cbdacf78f2c.tar.gz
mruby-85075bef7583edd0a48cfbdfaa632cbdacf78f2c.zip
simplify all IS* and TO* macros
Reduces the file size (by up to 2 KB with VS2015 RC, /O2, /MD) and removes the requirement of including <ctype.h> before their usage. Multiple macro argument evaluation and lack of type-checking is still an issue.
Diffstat (limited to 'include')
-rw-r--r--include/mruby.h25
1 files changed, 12 insertions, 13 deletions
diff --git a/include/mruby.h b/include/mruby.h
index bd6439931..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) ((unsigned)(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 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);