FreeBSD/usr.sbin/ypldap/aldap.c
/*
 * Strip UTF-8 down to ASCII without validation.
 * notes:
 *	non-ASCII characters are displayed as '?'
 *	the argument u should be a NULL terminated sequence of UTF-8 bytes.
 */
Strip UTF-8 down to ASCII without validation.
notes:
non-ASCII characters are displayed as '?'
the argument u should be a NULL terminated sequence of UTF-8 bytes.
Strip UTF - 8 down to ASCII without validation . notes : non - ASCII characters are displayed as ' ? ' the argument u should be a NULL terminated sequence of UTF - 8 bytes .
char *
utoa(char *u)
{
	int	 len, i, j;
	char	*str;
	for (len = 0, i = 0; u[i] != '\0'; i++)
		if (!isu8cont(u[i]))
			len++;
	if ((str = calloc(len + 1, sizeof(char))) == NULL)
		return NULL;
	for (i = 0, j = 0; u[i] != '\0'; i++)
		if (!isu8cont(u[i]))
			str[j++] = isascii((unsigned char)u[i]) ? u[i] : '?';
	return str;
}
char * utoa ( char * u ) { int len , i , j ; char * str ; for ( len = 0 , i = 0 ; u [ i ] != ' \0 ' ; i ++ ) if ( ! isu8cont ( u [ i ] ) ) len ++ ; if ( ( str = calloc ( len + 1 , sizeof ( char ) ) ) == NULL ) return NULL ; for ( i = 0 , j = 0 ; u [ i ] != ' \0 ' ; i ++ ) if ( ! isu8cont ( u [ i ] ) ) str [ j ++ ] = isascii ( ( unsigned char ) u [ i ] ) ? u [ i ] : ' ' ; return str ; }
Strip UTF-8 down to ASCII without validation.
Strip UTF - 8 down to ASCII without validation .
/* calculate the length to allocate */ /* copy the ASCII characters to the newly allocated string */