diff options
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/include/wchar.h | 2 | ||||
-rw-r--r-- | newlib/libc/string/Makefile.am | 5 | ||||
-rw-r--r-- | newlib/libc/string/Makefile.in | 15 | ||||
-rw-r--r-- | newlib/libc/string/wcstrings.tex | 8 | ||||
-rw-r--r-- | newlib/libc/string/wcswidth.c | 56 | ||||
-rw-r--r-- | newlib/libc/string/wcwidth.c | 53 |
6 files changed, 132 insertions, 7 deletions
diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h index 9a25f0c7a..8d3e4d9ee 100644 --- a/newlib/libc/include/wchar.h +++ b/newlib/libc/include/wchar.h @@ -62,6 +62,8 @@ wchar_t *_EXFUN(wcspbrk, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsrchr, (const wchar_t *, wchar_t)); size_t _EXFUN(wcsspn, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsstr, (const wchar_t *, const wchar_t *)); +int _EXFUN(wcswidth, (const wchar_t *, size_t)); +int _EXFUN(wcwidth, (const wchar_t)); wchar_t *_EXFUN(wmemchr, (const wchar_t *, wchar_t, size_t)); int _EXFUN(wmemcmp, (const wchar_t *, const wchar_t *, size_t)); wchar_t *_EXFUN(wmemcpy, (wchar_t * , const wchar_t * , size_t)); diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index ea7cace9d..6066c9bbf 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -61,6 +61,8 @@ GENERAL_SOURCES = \ wcsrchr.c \ wcsspn.c \ wcsstr.c \ + wcswidth.c \ + wcwidth.c \ wmemchr.c \ wmemcmp.c \ wmemcpy.c \ @@ -109,7 +111,8 @@ wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def \ wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wmemchr.def wmemcmp.def wmemcpy.def wmemmove.def wmemset.def +wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ +wmemmove.def wmemset.def SUFFIXES = .def diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index d2a3c7bc7..b53356c9e 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -167,6 +167,8 @@ GENERAL_SOURCES = \ wcsrchr.c \ wcsspn.c \ wcsstr.c \ + wcswidth.c \ + wcwidth.c \ wmemchr.c \ wmemcmp.c \ wmemcpy.c \ @@ -207,7 +209,8 @@ wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def \ wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wmemchr.def wmemcmp.def wmemcpy.def wmemmove.def wmemset.def +wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ +wmemmove.def wmemset.def SUFFIXES = .def @@ -246,9 +249,9 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@wcslcpy.$(OBJEXT) wcslen.$(OBJEXT) wcsncat.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcsncmp.$(OBJEXT) wcsncpy.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcspbrk.$(OBJEXT) wcsrchr.$(OBJEXT) wcsspn.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wcsstr.$(OBJEXT) wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemcpy.$(OBJEXT) wmemmove.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemset.$(OBJEXT) +@USE_LIBTOOL_FALSE@wcsstr.$(OBJEXT) wcswidth.$(OBJEXT) wcwidth.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) wmemcpy.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemmove.$(OBJEXT) wmemset.$(OBJEXT) LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@libstring_la_OBJECTS = bcopy.lo bzero.lo index.lo \ @@ -263,8 +266,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@wcscat.lo wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo \ @USE_LIBTOOL_TRUE@wcscspn.lo wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo \ @USE_LIBTOOL_TRUE@wcsncmp.lo wcsncpy.lo wcspbrk.lo wcsrchr.lo wcsspn.lo \ -@USE_LIBTOOL_TRUE@wcsstr.lo wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \ -@USE_LIBTOOL_TRUE@wmemset.lo +@USE_LIBTOOL_TRUE@wcsstr.lo wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ +@USE_LIBTOOL_TRUE@wmemcpy.lo wmemmove.lo wmemset.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/string/wcstrings.tex b/newlib/libc/string/wcstrings.tex index 7c72eab54..8f82e62c3 100644 --- a/newlib/libc/string/wcstrings.tex +++ b/newlib/libc/string/wcstrings.tex @@ -27,6 +27,8 @@ declarations are in @file{wchar.h}. * wcsrchr:: Reverse search for wide-character in string * wcsspn:: Find initial match in wide-character string * wcsstr:: Find wide-character string segment +* wcswidth:: Number of column positions of a wide-character string +* wcwidth:: Number of column positions of a wide-character code @end menu @page @@ -92,3 +94,9 @@ declarations are in @file{wchar.h}. @page @include string/wcsstr.def +@page +@include string/wcswidth.def + +@page +@include string/wcwidth.def + diff --git a/newlib/libc/string/wcswidth.c b/newlib/libc/string/wcswidth.c new file mode 100644 index 000000000..bd3d9bbad --- /dev/null +++ b/newlib/libc/string/wcswidth.c @@ -0,0 +1,56 @@ +/* +FUNCTION + <<wcswidth>>---number of column positions of a wide-character string + +INDEX + wcswidth + +ANSI_SYNOPSIS + #include <wchar.h> + int wcswidth(const wchar_t *<[pwcs]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include <wchar.h> + int wcswidth(<[pwcs]>, <[n]>) + wchar_t *<[wc]>; + size_t <[n]>; + +DESCRIPTION + The <<wcswidth>> function shall determine the number of column + positions required for n wide-character codes (or fewer than n + wide-character codes if a null wide-character code is encountered + before n wide-character codes are exhausted) in the string pointed + to by pwcs. + +RETURNS + The <<wcswidth>> function either shall return 0 (if pwcs points to a + null wide-character code), or return the number of column positions + to be occupied by the wide-character string pointed to by pwcs, or + return -1 (if any of the first n wide-character codes in the + wide-character string pointed to by pwcs is not a printable + wide-character code). + +PORTABILITY +<<wcswidth>> has been introduced in the Single UNIX Specification Volume 2 +<<wcswidth>> has been marked as extension in Single UNIX Specification Volume 3 +*/ + +#include <_ansi.h> +#include <wchar.h> + +int +_DEFUN (wcswidth, (pwcs, n), + _CONST wchar_t *pwcs _AND + size_t n) + +{ + int w, len = 0; + if (!pwcs || n == 0) + return 0; + do { + if ((w = wcwidth (*pwcs)) < 0) + return -1; + len += w; + } while (*pwcs++ && --n > 0); + return len; +} 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 + <<wcwidth>>---number of column positions of a wide-character code + +INDEX + wcwidth + +ANSI_SYNOPSIS + #include <wchar.h> + int wcwidth(const wchar_t <[wc]>); + +TRAD_SYNOPSIS + #include <wchar.h> + int wcwidth(<[wc]>) + wchar_t *<[wc]>; + +DESCRIPTION + The <<wcwidth>> 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 <<wcwidth>> 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 <<wcwidth>> simply sets the width + of all printable characters to 1 since newlib has no character + tables around. + +PORTABILITY +<<wcwidth>> has been introduced in the Single UNIX Specification Volume 2 +<<wcwidth>> has been marked as extension in Single UNIX Specification Volume 3 +*/ + +#include <_ansi.h> +#include <wchar.h> +#include <wctype.h> + +int +_DEFUN (wcwidth, (wc), + _CONST wchar_t wc) + +{ + if (iswprint (wc)) + return 1; + if (iswcntrl (wc) || wc == L'\0') + return 0; + return -1; +} |