Commit log from Dragonfly:

FreeBSD extended ctypes to include numbers (e.g. isnumber()) but never
actually implemented it.  The isnumber() function was equivalent to the
isdigit() function in every case.

Now that DragonFly's ctype source files have number definitions, the
number ctype can finally be implemented.  It's given a new flag _CTYPE_N.
The isalnum() and iswalnum() functions have been changed to use this
flag rather than the _CTYPE_D digit flag.

While isalnum(), isnumber(), and their wide equivalents now return
different values in locale cases, the ishexnumber() and iswhexnumber()
functions are unchanged.  They are still aliases for isxdigit() and
iswxdigit().

Also change ctype.h for isdigit and isxdigit to use sbistype like the
other functions.

Obtained from:	dragonfly
This commit is contained in:
Baptiste Daroussin 2015-10-13 20:43:49 +00:00
parent 7cefd8ca2a
commit f5dde0166d
9 changed files with 37 additions and 29 deletions

View File

@ -59,6 +59,7 @@
#define _CTYPE_I 0x00080000L /* Ideogram */
#define _CTYPE_T 0x00100000L /* Special */
#define _CTYPE_Q 0x00200000L /* Phonogram */
#define _CTYPE_N 0x00400000L /* Number (superset of digit) */
#define _CTYPE_SW0 0x20000000L /* 0 width character */
#define _CTYPE_SW1 0x40000000L /* 1 width character */
#define _CTYPE_SW2 0x80000000L /* 2 width character */

View File

@ -85,17 +85,17 @@ int isspecial(int);
__END_DECLS
#ifndef __cplusplus
#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D)
#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D|_CTYPE_N)
#define isalpha(c) __sbistype((c), _CTYPE_A)
#define iscntrl(c) __sbistype((c), _CTYPE_C)
#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
#define isdigit(c) __sbistype((c), _CTYPE_D)
#define isgraph(c) __sbistype((c), _CTYPE_G)
#define islower(c) __sbistype((c), _CTYPE_L)
#define isprint(c) __sbistype((c), _CTYPE_R)
#define ispunct(c) __sbistype((c), _CTYPE_P)
#define isspace(c) __sbistype((c), _CTYPE_S)
#define isupper(c) __sbistype((c), _CTYPE_U)
#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
#define isxdigit(c) __sbistype((c), _CTYPE_X)
#define tolower(c) __sbtolower(c)
#define toupper(c) __sbtoupper(c)
#endif /* !__cplusplus */
@ -126,7 +126,7 @@ __END_DECLS
#define digittoint(c) __sbmaskrune((c), 0xFF)
#define ishexnumber(c) __sbistype((c), _CTYPE_X)
#define isideogram(c) __sbistype((c), _CTYPE_I)
#define isnumber(c) __sbistype((c), _CTYPE_D)
#define isnumber(c) __sbistype((c), _CTYPE_D|_CTYPE_N)
#define isphonogram(c) __sbistype((c), _CTYPE_Q)
#define isrune(c) __sbistype((c), 0xFFFFFF00L)
#define isspecial(c) __sbistype((c), _CTYPE_T)

View File

@ -95,27 +95,27 @@ wint_t nextwctype(wint_t, wctype_t);
__END_DECLS
#ifndef __cplusplus
#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D)
#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D|_CTYPE_N)
#define iswalpha(wc) __istype((wc), _CTYPE_A)
#define iswblank(wc) __istype((wc), _CTYPE_B)
#define iswcntrl(wc) __istype((wc), _CTYPE_C)
#define iswctype(wc, charclass) __istype((wc), (charclass))
#define iswdigit(wc) __isctype((wc), _CTYPE_D)
#define iswdigit(wc) __istype((wc), _CTYPE_D)
#define iswgraph(wc) __istype((wc), _CTYPE_G)
#define iswlower(wc) __istype((wc), _CTYPE_L)
#define iswprint(wc) __istype((wc), _CTYPE_R)
#define iswpunct(wc) __istype((wc), _CTYPE_P)
#define iswspace(wc) __istype((wc), _CTYPE_S)
#define iswupper(wc) __istype((wc), _CTYPE_U)
#define iswxdigit(wc) __isctype((wc), _CTYPE_X)
#define iswxdigit(wc) __istype((wc), _CTYPE_X)
#define towlower(wc) __tolower(wc)
#define towupper(wc) __toupper(wc)
#if __BSD_VISIBLE
#define iswascii(wc) (((wc) & ~0x7F) == 0)
#define iswhexnumber(wc) __istype((wc), _CTYPE_X)
#define iswhexnumber(wc) __istype((wc), _CTYPE_X) /* alias of iswxdigit */
#define iswideogram(wc) __istype((wc), _CTYPE_I)
#define iswnumber(wc) __istype((wc), _CTYPE_D)
#define iswnumber(wc) __istype((wc), _CTYPE_D|_CTYPE_N)
#define iswphonogram(wc) __istype((wc), _CTYPE_Q)
#define iswrune(wc) __istype((wc), 0xFFFFFF00L)
#define iswspecial(wc) __istype((wc), _CTYPE_T)

View File

@ -119,7 +119,7 @@ __sbistype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc)
{ return __sbistype_l(__c, __cat, __l); }
#endif
XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D)
XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D|_CTYPE_N)
XLOCALE_ISCTYPE(alpha, _CTYPE_A)
XLOCALE_ISCTYPE(blank, _CTYPE_B)
XLOCALE_ISCTYPE(cntrl, _CTYPE_C)
@ -128,7 +128,7 @@ XLOCALE_ISCTYPE(graph, _CTYPE_G)
XLOCALE_ISCTYPE(hexnumber, _CTYPE_X)
XLOCALE_ISCTYPE(ideogram, _CTYPE_I)
XLOCALE_ISCTYPE(lower, _CTYPE_L)
XLOCALE_ISCTYPE(number, _CTYPE_D)
XLOCALE_ISCTYPE(number, _CTYPE_D|_CTYPE_N)
XLOCALE_ISCTYPE(phonogram, _CTYPE_Q)
XLOCALE_ISCTYPE(print, _CTYPE_R)
XLOCALE_ISCTYPE(punct, _CTYPE_P)

View File

@ -54,7 +54,7 @@ digittoint(int c)
int
isalnum(int c)
{
return (__sbistype(c, _CTYPE_A|_CTYPE_D));
return (__sbistype(c, _CTYPE_A|_CTYPE_N));
}
#undef isalpha
@ -124,7 +124,7 @@ islower(int c)
int
isnumber(int c)
{
return (__sbistype(c, _CTYPE_D));
return (__sbistype(c, _CTYPE_N));
}
#undef isphonogram

View File

@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
int
iswalnum(wint_t wc)
{
return (__istype(wc, _CTYPE_A|_CTYPE_D));
return (__istype(wc, _CTYPE_A|_CTYPE_N));
}
#undef iswalpha
@ -79,7 +79,7 @@ iswcntrl(wint_t wc)
int
iswdigit(wint_t wc)
{
return (__isctype(wc, _CTYPE_D));
return (__istype(wc, _CTYPE_D));
}
#undef iswgraph
@ -114,7 +114,7 @@ iswlower(wint_t wc)
int
iswnumber(wint_t wc)
{
return (__istype(wc, _CTYPE_D));
return (__istype(wc, _CTYPE_N));
}
#undef iswphonogram
@ -170,7 +170,7 @@ iswupper(wint_t wc)
int
iswxdigit(wint_t wc)
{
return (__isctype(wc, _CTYPE_X));
return (__istype(wc, _CTYPE_X));
}
#undef towlower

View File

@ -101,16 +101,16 @@ const _RuneLocale _DefaultRuneLocale = {
_CTYPE_P|_CTYPE_R|_CTYPE_G,
_CTYPE_P|_CTYPE_R|_CTYPE_G,
_CTYPE_P|_CTYPE_R|_CTYPE_G,
/*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|0,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|1,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|2,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|3,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|4,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|5,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|6,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|7,
/*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|8,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|9,
/*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|0,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|1,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|2,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|3,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|4,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|5,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|6,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|7,
/*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|8,
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|9,
_CTYPE_P|_CTYPE_R|_CTYPE_G,
_CTYPE_P|_CTYPE_R|_CTYPE_G,
_CTYPE_P|_CTYPE_R|_CTYPE_G,

View File

@ -73,9 +73,10 @@ wctype_l(const char *property, locale_t locale)
"ideogram\0" /* BSD extension */
"special\0" /* BSD extension */
"phonogram\0" /* BSD extension */
"number\0" /* BSD extension */
"rune\0"; /* BSD extension */
static const wctype_t propmasks[] = {
_CTYPE_A|_CTYPE_D,
_CTYPE_A|_CTYPE_N,
_CTYPE_A,
_CTYPE_B,
_CTYPE_C,
@ -90,6 +91,7 @@ wctype_l(const char *property, locale_t locale)
_CTYPE_I,
_CTYPE_T,
_CTYPE_Q,
_CTYPE_N,
0xFFFFFF00L
};
size_t len1, len2;

View File

@ -51,6 +51,11 @@ __FBSDID("$FreeBSD$");
#include "runefile.h"
/* Needed for bootstrapping, _CTYPE_N */
#ifndef _CTYPE_N
#define _CTYPE_N 0x00400000L
#endif
#define _ISUPPER _CTYPE_U
#define _ISLOWER _CTYPE_L
#define _ISDIGIT _CTYPE_D
@ -65,7 +70,7 @@ __FBSDID("$FreeBSD$");
#define _E1 _CTYPE_Q
#define _E2 _CTYPE_I
#define _E3 0
#define _E4 0
#define _E4 _CTYPE_N
#define _E5 _CTYPE_T
static wchar_t last_ctype;