diff options
| author | Andrey A. Chernov <ache@FreeBSD.org> | 1995-02-16 17:01:11 +0000 | 
|---|---|---|
| committer | Andrey A. Chernov <ache@FreeBSD.org> | 1995-02-16 17:01:11 +0000 | 
| commit | a4d5d0cbdee7cf7db081405b6e7acd8c7200ddea (patch) | |
| tree | fd56650da90e965a9b2905d78e13f77db07c775a /lib/libc/string/strxfrm.c | |
| parent | 96658fee5a8cfe17dfd970b683958eee579bfa65 (diff) | |
Notes
Diffstat (limited to 'lib/libc/string/strxfrm.c')
| -rw-r--r-- | lib/libc/string/strxfrm.c | 99 | 
1 files changed, 64 insertions, 35 deletions
| diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c index 0d6fcb48da8c..73206decacaa 100644 --- a/lib/libc/string/strxfrm.c +++ b/lib/libc/string/strxfrm.c @@ -1,9 +1,7 @@  /*- - * Copyright (c) 1990, 1993 - *	The Regents of the University of California.  All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. + * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> + *		at Electronni Visti IA, Kiev, Ukraine. + *			All rights reserved.   *   * Redistribution and use in source and binary forms, with or without   * modification, are permitted provided that the following conditions @@ -13,18 +11,11 @@   * 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR 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) @@ -32,36 +23,74 @@   * 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. + * + * $Id: strxfrm.c,v 1.5 1995/01/27 12:51:06 alex Exp alex $   */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strxfrm.c	8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/cdefs.h> +#include <stdlib.h>  #include <string.h> +#include "collate.h"  /* - * Transform src, storing the result in dst, such that - * strcmp() on transformed strings returns what strcoll() - * on the original untransformed strings would return. + * Transform src, storing the result in dest, such that strcmp() + * on transformed strings returns what strcoll() on the original + * untransformed strings would return.   */ +  size_t -strxfrm(dst, src, n) -	register char *dst; +strxfrm(dest, src, len) +	char *dest;  	const char *src; -	size_t n; +	size_t len;  { -	register size_t srclen, copysize; +	int prim, sec, l; +	char *d = dest, *s, *ss; + +	if (len < 1) +		return 0; + +	if (!*src) { +		*d = '\0'; +		return 0; +	} + +	if (__collate_load_error) { +		size_t slen, ncopy; + +		slen = strlen(src); +		ncopy = slen < len ? slen : len - 1; +		(void)memcpy(d, src, ncopy); +		d[ncopy] = '\0'; +		return ncopy; +	} -	/* -	 * Since locales are unimplemented, this is just a copy. -	 */ -	srclen = strlen(src); -	if (n != 0) { -		copysize = srclen < n ? srclen : n - 1; -		(void)memcpy(dst, src, copysize); -		dst[copysize] = 0; +	ss = s = __collate_substitute(src); +	prim = sec = 0; +	while (*s && len > 1) { +		while (*s && !prim) { +			__collate_lookup(s, &l, &prim, &sec); +			s += l; +		} +		if (prim) { +			*d++ = (char)prim; +			len--; +		} +	} +#if 0 +	s = ss; +	while (*s && len > 1) { +		while (*s && !prim) { +			lookup(s, &l, &prim, &sec); +			s += l; +		} +		if (prim && sec) { +			*d++ = (char)sec; +			len--; +		}  	} -	return (srclen); +#endif /* 0 */ +	*d = '\0'; +	free(ss); + +	return d - dest;  } | 
