Skip to content

Commit 8496112

Browse files
committed
Better documentation for 'lctype.h'
The old documentation said that 'ltolower' only works for alphabetic characters. However, 'l_str2d' uses it (correctly) also on dots ('.').
1 parent 6bc0f13 commit 8496112

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lctype.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/*
1414
** WARNING: the functions defined here do not necessarily correspond
1515
** to the similar functions in the standard C ctype.h. They are
16-
** optimized for the specific needs of Lua
16+
** optimized for the specific needs of Lua.
1717
*/
1818

1919
#if !defined(LUA_USE_CTYPE)
@@ -61,13 +61,19 @@
6161
#define lisprint(c) testprop(c, MASK(PRINTBIT))
6262
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
6363

64+
6465
/*
65-
** this 'ltolower' only works for alphabetic characters
66+
** In ASCII, this 'ltolower' is correct for alphabetic characters and
67+
** for '.'. That is enough for Lua needs. ('check_exp' ensures that
68+
** the character either is an upper-case letter or is unchanged by
69+
** the transformation, which holds for lower-case letters and '.'.)
6670
*/
67-
#define ltolower(c) ((c) | ('A' ^ 'a'))
71+
#define ltolower(c) \
72+
check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
73+
(c) | ('A' ^ 'a'))
6874

6975

70-
/* two more entries for 0 and -1 (EOZ) */
76+
/* one entry for each character and for -1 (EOZ) */
7177
LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
7278

7379

0 commit comments

Comments
 (0)