* 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.
This commit is contained in:
Corinna Vinschen 2003-04-09 10:42:12 +00:00
parent 774d9e8282
commit 8f8d09c041
7 changed files with 141 additions and 7 deletions

View File

@ -1,3 +1,12 @@
2001-04-09 Corinna Vinschen <corinna@vinschen.de>
* 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.
Thu Apr 3 14:01:16 2003 J"orn Rennecke <joern.rennecke@superh.com>
* libc/machine/sh/memset.S: Fix problem with alloco region

View File

@ -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));

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}