diff options
author | ache <ache@FreeBSD.org> | 2002-08-20 02:06:28 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2002-08-20 02:06:28 +0000 |
commit | a2d28129a1dc6ba8790a2b615588e2801bc485eb (patch) | |
tree | 895ff35d91112d35448e74d7b5cb2546808efdd8 /lib/libc/string | |
parent | 87f08c9cbb7749dfd672d399401d9e77ae318f41 (diff) | |
download | FreeBSD-src-a2d28129a1dc6ba8790a2b615588e2801bc485eb.zip FreeBSD-src-a2d28129a1dc6ba8790a2b615588e2801bc485eb.tar.gz |
Move just committed version of wcswidth.c here (from "locale"),
a bit optimized now.
Diffstat (limited to 'lib/libc/string')
-rw-r--r-- | lib/libc/string/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/string/wcswidth.c | 54 |
2 files changed, 31 insertions, 25 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 457fb76..8dd1092 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -14,7 +14,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \ strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ strxfrm.c swab.c wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c \ wcslcat.c wcslcpy.c wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c \ - wcsrchr.c wcsspn.c wcsstr.c wmemchr.c wmemcmp.c wmemcpy.c \ + wcsrchr.c wcsspn.c wcsstr.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ wmemmove.c wmemset.c diff --git a/lib/libc/string/wcswidth.c b/lib/libc/string/wcswidth.c index 84dc42b..553e6d2 100644 --- a/lib/libc/string/wcswidth.c +++ b/lib/libc/string/wcswidth.c @@ -1,6 +1,14 @@ -/*- - * Copyright (c)1999 Citrus Project, - * All rights reserved. +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,11 +18,18 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -22,34 +37,25 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp */ #include <sys/cdefs.h> -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcswidth.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif __FBSDID("$FreeBSD$"); -#include <assert.h> #include <wchar.h> int -wcswidth(s, n) - const wchar_t *s; - size_t n; +wcswidth(const wchar_t *pwcs, size_t n) { - int w; + wchar_t wc; + int len, l; - w = 0; - while (n && *s) { - w += wcwidth(*s); - s++; - n--; + len = 0; + while (n-- > 0 && (wc = *pwcs++) != L'\0') { + if ((l = wcwidth(wc)) < 0) + return (-1); + len += l; } - - return w; + return (len); } + |