summaryrefslogtreecommitdiff
path: root/lctype.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-06-24 09:25:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-06-24 09:25:33 -0300
commit6eadedbfa10bcc4a9d7b0694e48686105d86538f (patch)
treefc882740e1d138452c2d41b22c87924cd3f5d03c /lctype.h
parent1978094b3a914930bd5aee2aaf830c8ff1410b9a (diff)
downloadlua-github-6eadedbfa10bcc4a9d7b0694e48686105d86538f.tar.gz
resort to standard C ctype for non-ASCII systems + 'ltoupper' replaced
by 'ltolower'
Diffstat (limited to 'lctype.h')
-rw-r--r--lctype.h47
1 files changed, 41 insertions, 6 deletions
diff --git a/lctype.h b/lctype.h
index 4c33e8cd..171bb5eb 100644
--- a/lctype.h
+++ b/lctype.h
@@ -1,5 +1,5 @@
/*
-** $Id: lctype.h,v 1.8 2009/11/19 19:06:52 roberto Exp roberto $
+** $Id: lctype.h,v 1.9 2011/06/23 16:00:43 roberto Exp roberto $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
*/
@@ -7,6 +7,8 @@
#ifndef lctype_h
#define lctype_h
+#include "lua.h"
+
/*
** WARNING: the functions defined here do not necessarily correspond
@@ -14,10 +16,22 @@
** optimized for the specific needs of Lua
*/
+#if !defined(LUA_USE_CTYPE)
-#include <limits.h>
+#if 'A' == 65 && '0' == 48
+/* ASCII case: can use its own tables; faster and fixed */
+#define LUA_USE_CTYPE 0
+#else
+/* must use standard C ctype */
+#define LUA_USE_CTYPE 1
+#endif
-#include "lua.h"
+#endif
+
+
+#if !LUA_USE_CTYPE /* { */
+
+#include <limits.h>
#include "llimits.h"
@@ -48,13 +62,34 @@
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
/*
-** this 'ltoupper' only works for alphabetic characters
+** this 'ltolower' only works for alphabetic characters
*/
-#define ltoupper(c) ((c) & ~32)
+#define ltolower(c) ((c) | 32)
-/* one more entry for 0 and one more for -1 (EOZ) */
+/* two more entries for 0 and -1 (EOZ) */
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
+
+#else /* }{ */
+
+/*
+** use standard C ctypes
+*/
+
+#include <ctype.h>
+
+
+#define lislalpha(c) (isalpha(c) || (c) == '_')
+#define lislalnum(c) (isalnum(c) || (c) == '_')
+#define lisdigit(c) (isdigit(c))
+#define lisspace(c) (isspace(c))
+#define lisprint(c) (isprint(c))
+#define lisxdigit(c) (isxdigit(c))
+
+#define ltolower(c) (tolower(c))
+
+#endif /* } */
+
#endif