Implement wcwidth() as an inline function.
This commit is contained in:
parent
b9de27c005
commit
de6c9c9d5b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=133564
@ -67,6 +67,8 @@
|
|||||||
#define _CTYPE_SW1 0x40000000L /* 1 width character */
|
#define _CTYPE_SW1 0x40000000L /* 1 width character */
|
||||||
#define _CTYPE_SW2 0x80000000L /* 2 width character */
|
#define _CTYPE_SW2 0x80000000L /* 2 width character */
|
||||||
#define _CTYPE_SW3 0xc0000000L /* 3 width character */
|
#define _CTYPE_SW3 0xc0000000L /* 3 width character */
|
||||||
|
#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
|
||||||
|
#define _CTYPE_SWS 30 /* Bits to shift to get width */
|
||||||
|
|
||||||
/* See comments in <sys/_types.h> about __ct_rune_t. */
|
/* See comments in <sys/_types.h> about __ct_rune_t. */
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
@ -127,6 +129,19 @@ __tolower(__ct_rune_t _c)
|
|||||||
_CurrentRuneLocale->__maplower[_c];
|
_CurrentRuneLocale->__maplower[_c];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __inline int
|
||||||
|
__wcwidth(__ct_rune_t _c)
|
||||||
|
{
|
||||||
|
unsigned int _x;
|
||||||
|
|
||||||
|
if (_c == 0)
|
||||||
|
return (0);
|
||||||
|
_x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
|
||||||
|
if ((_x & _CTYPE_SWM) != 0)
|
||||||
|
return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
|
||||||
|
return ((_x & _CTYPE_R) != 0 ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
#else /* not using inlines */
|
#else /* not using inlines */
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
@ -135,6 +150,7 @@ int __istype(__ct_rune_t, unsigned long);
|
|||||||
int __isctype(__ct_rune_t, unsigned long);
|
int __isctype(__ct_rune_t, unsigned long);
|
||||||
__ct_rune_t __toupper(__ct_rune_t);
|
__ct_rune_t __toupper(__ct_rune_t);
|
||||||
__ct_rune_t __tolower(__ct_rune_t);
|
__ct_rune_t __tolower(__ct_rune_t);
|
||||||
|
int __wcwidth(__ct_rune_t);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
#endif /* using inlines */
|
#endif /* using inlines */
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
#include <sys/_null.h>
|
#include <sys/_null.h>
|
||||||
#include <sys/_types.h>
|
#include <sys/_types.h>
|
||||||
#include <machine/_limits.h>
|
#include <machine/_limits.h>
|
||||||
|
#include <_ctype.h>
|
||||||
|
|
||||||
#ifndef _MBSTATE_T_DECLARED
|
#ifndef _MBSTATE_T_DECLARED
|
||||||
typedef __mbstate_t mbstate_t;
|
typedef __mbstate_t mbstate_t;
|
||||||
@ -206,6 +207,7 @@ unsigned long long
|
|||||||
#if __XSI_VISIBLE
|
#if __XSI_VISIBLE
|
||||||
int wcswidth(const wchar_t *, size_t);
|
int wcswidth(const wchar_t *, size_t);
|
||||||
int wcwidth(wchar_t);
|
int wcwidth(wchar_t);
|
||||||
|
#define wcwidth(_c) __wcwidth(_c)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __BSD_VISIBLE
|
#if __BSD_VISIBLE
|
||||||
|
@ -43,21 +43,12 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
|
||||||
|
|
||||||
#define _CTYPE_SWM 0xe0000000L /* Mask to get screen width data */
|
#undef wcwidth
|
||||||
#define _CTYPE_SWS 30 /* Bits to shift to get width */
|
|
||||||
|
|
||||||
int
|
int
|
||||||
wcwidth(wchar_t wc)
|
wcwidth(wchar_t wc)
|
||||||
{
|
{
|
||||||
unsigned int x;
|
|
||||||
|
|
||||||
if (wc == L'\0')
|
return (__wcwidth(wc));
|
||||||
return (0);
|
|
||||||
|
|
||||||
x = (unsigned int)__maskrune(wc, _CTYPE_SWM|_CTYPE_R);
|
|
||||||
if ((x & _CTYPE_SWM) != 0)
|
|
||||||
return ((x & _CTYPE_SWM) >> _CTYPE_SWS);
|
|
||||||
return ((x & _CTYPE_R) != 0 ? 1 : -1);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user