Fix isspecial/isphonogram, they was swapped

Remove EOF hack, now it is recognized per ANSI/POSIX
Add upper bounds check
Handle all negative chars inside locale functions
This commit is contained in:
ache 1995-11-03 12:25:14 +00:00
parent c41fb99a39
commit d402cb649b
2 changed files with 26 additions and 36 deletions

View File

@ -111,9 +111,9 @@ __END_DECLS
#define ishexnumber(c) __istype((c), _X)
#define isideogram(c) __istype((c), _I)
#define isnumber(c) __istype((c), _D)
#define isphonogram(c) __istype((c), _T)
#define isphonogram(c) __istype((c), _Q)
#define isrune(c) __istype((c), 0xFFFFFF00L)
#define isspecial(c) __istype((c), _Q)
#define isspecial(c) __istype((c), _T)
#endif
/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
@ -141,37 +141,32 @@ __END_DECLS
static __inline int
__istype(_BSD_RUNE_T_ _c, unsigned long _f)
{
if (_c < 0)
_c = (unsigned char) _c;
return((((_c & _CRMASK) ? ___runetype(_c) :
_CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0);
return (_c < 0 || _c & _CRMASK) ? !!(___runetype(_c) & _f) :
(_c >= _CACHED_RUNES) ? 0 :
!!(_CurrentRuneLocale->runetype[_c] & _f);
}
static __inline int
__isctype(_BSD_RUNE_T_ _c, unsigned long _f)
{
if (_c < 0)
_c = (unsigned char) _c;
return((((_c & _CRMASK) ? 0 :
_DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0);
return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
!!(_DefaultRuneLocale.runetype[_c] & _f);
}
static __inline _BSD_RUNE_T_
__toupper(_BSD_RUNE_T_ _c)
{
if (_c < 0)
_c = (unsigned char) _c;
return((_c & _CRMASK) ?
___toupper(_c) : _CurrentRuneLocale->mapupper[_c]);
return (_c < 0 || _c & _CRMASK) ? ___toupper(_c) :
(_c >= _CACHED_RUNES) ? _c :
_CurrentRuneLocale->mapupper[_c];
}
static __inline _BSD_RUNE_T_
__tolower(_BSD_RUNE_T_ _c)
{
if (_c < 0)
_c = (unsigned char) _c;
return((_c & _CRMASK) ?
___tolower(_c) : _CurrentRuneLocale->maplower[_c]);
return (_c < 0 || _c & _CRMASK) ? ___tolower(_c) :
(_c >= _CACHED_RUNES) ? _c :
_CurrentRuneLocale->maplower[_c];
}
#else /* not using inlines */

View File

@ -111,9 +111,9 @@ __END_DECLS
#define ishexnumber(c) __istype((c), _X)
#define isideogram(c) __istype((c), _I)
#define isnumber(c) __istype((c), _D)
#define isphonogram(c) __istype((c), _T)
#define isphonogram(c) __istype((c), _Q)
#define isrune(c) __istype((c), 0xFFFFFF00L)
#define isspecial(c) __istype((c), _Q)
#define isspecial(c) __istype((c), _T)
#endif
/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
@ -141,37 +141,32 @@ __END_DECLS
static __inline int
__istype(_BSD_RUNE_T_ _c, unsigned long _f)
{
if (_c < 0)
_c = (unsigned char) _c;
return((((_c & _CRMASK) ? ___runetype(_c) :
_CurrentRuneLocale->runetype[_c]) & _f) ? 1 : 0);
return (_c < 0 || _c & _CRMASK) ? !!(___runetype(_c) & _f) :
(_c >= _CACHED_RUNES) ? 0 :
!!(_CurrentRuneLocale->runetype[_c] & _f);
}
static __inline int
__isctype(_BSD_RUNE_T_ _c, unsigned long _f)
{
if (_c < 0)
_c = (unsigned char) _c;
return((((_c & _CRMASK) ? 0 :
_DefaultRuneLocale.runetype[_c]) & _f) ? 1 : 0);
return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
!!(_DefaultRuneLocale.runetype[_c] & _f);
}
static __inline _BSD_RUNE_T_
__toupper(_BSD_RUNE_T_ _c)
{
if (_c < 0)
_c = (unsigned char) _c;
return((_c & _CRMASK) ?
___toupper(_c) : _CurrentRuneLocale->mapupper[_c]);
return (_c < 0 || _c & _CRMASK) ? ___toupper(_c) :
(_c >= _CACHED_RUNES) ? _c :
_CurrentRuneLocale->mapupper[_c];
}
static __inline _BSD_RUNE_T_
__tolower(_BSD_RUNE_T_ _c)
{
if (_c < 0)
_c = (unsigned char) _c;
return((_c & _CRMASK) ?
___tolower(_c) : _CurrentRuneLocale->maplower[_c]);
return (_c < 0 || _c & _CRMASK) ? ___tolower(_c) :
(_c >= _CACHED_RUNES) ? _c :
_CurrentRuneLocale->maplower[_c];
}
#else /* not using inlines */