summaryrefslogtreecommitdiffstats
path: root/include/_ctype.h
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-08-12 12:19:11 +0000
committertjr <tjr@FreeBSD.org>2004-08-12 12:19:11 +0000
commit84b5d3520fd89553036a69a6c1e0481f0b65d8ea (patch)
tree802ec2593ce866aa0d0473bfc2cd7c04d0f9cd00 /include/_ctype.h
parent0340faafa1e860a32729f20649b0e508d257006e (diff)
downloadFreeBSD-src-84b5d3520fd89553036a69a6c1e0481f0b65d8ea.zip
FreeBSD-src-84b5d3520fd89553036a69a6c1e0481f0b65d8ea.tar.gz
Implement wcwidth() as an inline function.
Diffstat (limited to 'include/_ctype.h')
-rw-r--r--include/_ctype.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/_ctype.h b/include/_ctype.h
index acea539..a1fc0a2 100644
--- a/include/_ctype.h
+++ b/include/_ctype.h
@@ -67,6 +67,8 @@
#define _CTYPE_SW1 0x40000000L /* 1 width character */
#define _CTYPE_SW2 0x80000000L /* 2 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. */
__BEGIN_DECLS
@@ -127,6 +129,19 @@ __tolower(__ct_rune_t _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 */
__BEGIN_DECLS
@@ -135,6 +150,7 @@ int __istype(__ct_rune_t, unsigned long);
int __isctype(__ct_rune_t, unsigned long);
__ct_rune_t __toupper(__ct_rune_t);
__ct_rune_t __tolower(__ct_rune_t);
+int __wcwidth(__ct_rune_t);
__END_DECLS
#endif /* using inlines */
OpenPOWER on IntegriCloud