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/wcswidth.c | |
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/wcswidth.c')
-rw-r--r-- | lib/libc/string/wcswidth.c | 54 |
1 files changed, 30 insertions, 24 deletions
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); } + |