From 8f8d09c041ffce812946f8bd6b4b388676e4e56e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 9 Apr 2003 10:42:12 +0000 Subject: * libc/include/wchar.h: Add definitions for wcswidth and wcwidth. * libc/string/Makefile.am: Add wcswidth.c and wcwidth.c * libc/string/Makefile.in: Regenerated. * libc/string/wcswidth.c: New file. * libc/string/wcwidth.c: New file. * libc/string/wcstrings.tex: Add wcswidth and wcwidth. --- newlib/libc/string/wcwidth.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 newlib/libc/string/wcwidth.c (limited to 'newlib/libc/string/wcwidth.c') diff --git a/newlib/libc/string/wcwidth.c b/newlib/libc/string/wcwidth.c new file mode 100644 index 000000000..2cbd59e18 --- /dev/null +++ b/newlib/libc/string/wcwidth.c @@ -0,0 +1,53 @@ +/* +FUNCTION + <>---number of column positions of a wide-character code + +INDEX + wcwidth + +ANSI_SYNOPSIS + #include + int wcwidth(const wchar_t <[wc]>); + +TRAD_SYNOPSIS + #include + int wcwidth(<[wc]>) + wchar_t *<[wc]>; + +DESCRIPTION + The <> function shall determine the number of column + positions required for the wide character wc. The application + shall ensure that the value of wc is a character representable + as a wchar_t, and is a wide-character code corresponding to a + valid character in the current locale. + +RETURNS + The <> function shall either return 0 (if wc is a null + wide-character code), or return the number of column positions to + be occupied by the wide-character code wc, or return -1 (if wc + does not correspond to a printable wide-character code). + + The current implementation of <> simply sets the width + of all printable characters to 1 since newlib has no character + tables around. + +PORTABILITY +<> has been introduced in the Single UNIX Specification Volume 2 +<> has been marked as extension in Single UNIX Specification Volume 3 +*/ + +#include <_ansi.h> +#include +#include + +int +_DEFUN (wcwidth, (wc), + _CONST wchar_t wc) + +{ + if (iswprint (wc)) + return 1; + if (iswcntrl (wc) || wc == L'\0') + return 0; + return -1; +} -- cgit v1.2.3