summaryrefslogtreecommitdiffstats
path: root/include/_ctype.h
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2007-10-13 16:28:22 +0000
committerache <ache@FreeBSD.org>2007-10-13 16:28:22 +0000
commita5038f060de9f1cc50cf532f78541dfd901f10b8 (patch)
tree364de71872fe91708dda5fd7ffeb957967a6f749 /include/_ctype.h
parent5b067f00c53dea274158508c1867eedfa02afea8 (diff)
downloadFreeBSD-src-a5038f060de9f1cc50cf532f78541dfd901f10b8.zip
FreeBSD-src-a5038f060de9f1cc50cf532f78541dfd901f10b8.tar.gz
The problem is: currently our single byte ctype(3) functions are broken
for wide characters locales in the argument range >= 0x80 - they may return false positives. Example 1: for UTF-8 locale we currently have: iswspace(0xA0)==1 and isspace(0xA0)==1 (because iswspace() and isspace() are the same code) but must have iswspace(0xA0)==1 and isspace(0xA0)==0 (because there is no such character and all others in the range 0x80..0xff for the UTF-8 locale, it keeps ASCII only in the single byte range because our internal wchar_t representation for UTF-8 is UCS-4). Example 2: for all wide character locales isalpha(arg) when arg > 0xFF may return false positives (must be 0). (because iswalpha() and isalpha() are the same code) This change address this issue separating single byte and wide ctype and also fix iswascii() (currently iswascii() is broken for arguments > 0xFF). This change is 100% binary compatible with old binaries. Reviewied by: i18n@
Diffstat (limited to 'include/_ctype.h')
-rw-r--r--include/_ctype.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/include/_ctype.h b/include/_ctype.h
index 1a42952..e27ab24 100644
--- a/include/_ctype.h
+++ b/include/_ctype.h
@@ -87,6 +87,8 @@ __END_DECLS
#define __inline
#endif
+extern int __mb_sb_limit;
+
/*
* Use inline functions if we are allowed to and the compiler supports them.
*/
@@ -103,15 +105,28 @@ __maskrune(__ct_rune_t _c, unsigned long _f)
}
static __inline int
+__sbmaskrune(__ct_rune_t _c, unsigned long _f)
+{
+ return (_c < 0 || _c >= __mb_sb_limit) ? 0 :
+ _CurrentRuneLocale->__runetype[_c] & _f;
+}
+
+static __inline int
__istype(__ct_rune_t _c, unsigned long _f)
{
return (!!__maskrune(_c, _f));
}
static __inline int
+__sbistype(__ct_rune_t _c, unsigned long _f)
+{
+ return (!!__sbmaskrune(_c, _f));
+}
+
+static __inline int
__isctype(__ct_rune_t _c, unsigned long _f)
{
- return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
+ return (_c < 0 || _c >= __mb_sb_limit) ? 0 :
!!(_DefaultRuneLocale.__runetype[_c] & _f);
}
@@ -123,12 +138,26 @@ __toupper(__ct_rune_t _c)
}
static __inline __ct_rune_t
+__sbtoupper(__ct_rune_t _c)
+{
+ return (_c < 0 || _c >= __mb_sb_limit) ? _c :
+ _CurrentRuneLocale->__mapupper[_c];
+}
+
+static __inline __ct_rune_t
__tolower(__ct_rune_t _c)
{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
_CurrentRuneLocale->__maplower[_c];
}
+static __inline __ct_rune_t
+__sbtolower(__ct_rune_t _c)
+{
+ return (_c < 0 || _c >= __mb_sb_limit) ? _c :
+ _CurrentRuneLocale->__maplower[_c];
+}
+
static __inline int
__wcwidth(__ct_rune_t _c)
{
@@ -146,10 +175,14 @@ __wcwidth(__ct_rune_t _c)
__BEGIN_DECLS
int __maskrune(__ct_rune_t, unsigned long);
+int __sbmaskrune(__ct_rune_t, unsigned long);
int __istype(__ct_rune_t, unsigned long);
+int __sbistype(__ct_rune_t, unsigned long);
int __isctype(__ct_rune_t, unsigned long);
__ct_rune_t __toupper(__ct_rune_t);
+__ct_rune_t __sbtoupper(__ct_rune_t);
__ct_rune_t __tolower(__ct_rune_t);
+__ct_rune_t __sbtolower(__ct_rune_t);
int __wcwidth(__ct_rune_t);
__END_DECLS
#endif /* using inlines */
OpenPOWER on IntegriCloud