libdispatch/dutf8.c
/*
 * Check validity of a UTF8 encoded null-terminated byte string.
 * Return codes:
 * NC_NOERR -- string is valid utf8
 * NC_ENOMEM -- out of memory
 * NC_EINVAL -- invalid argument or internal error
 * NC_EBADNAME-- not valid utf8
 */
Check validity of a UTF8 encoded null-terminated byte string.
Check validity of a UTF8 encoded null - terminated byte string .
int
nc_utf8_validate(const unsigned char* name)
{
    int ncstat = NC_NOERR;
    const nc_utf8proc_uint8_t *str;
    nc_utf8proc_ssize_t strlen = -1;
    nc_utf8proc_int32_t codepoint;
    nc_utf8proc_ssize_t count;
    str = (const nc_utf8proc_uint8_t*)name;
    while(*str) {
        count = nc_utf8proc_iterate(str,strlen,&codepoint);
	if(count < 0) {
	    switch (count) {
	    case UTF8PROC_ERROR_NOMEM:
	    case UTF8PROC_ERROR_OVERFLOW:
		ncstat = NC_ENOMEM;
		break;
	    case UTF8PROC_ERROR_INVALIDOPTS:
		ncstat = NC_EINVAL;
		break;
	    case UTF8PROC_ERROR_INVALIDUTF8:
	    case UTF8PROC_ERROR_NOTASSIGNED:
	    default:
		ncstat = NC_EBADNAME;
		break;
	    }
	    goto done;
	} else { 
	    str += count;
	}
    }
done:
    return ncstat;
}
int nc_utf8_validate ( const unsigned char * name ) { int ncstat = NC_NOERR ; const nc_utf8proc_uint8_t * str ; nc_utf8proc_ssize_t strlen = -1 ; nc_utf8proc_int32_t codepoint ; nc_utf8proc_ssize_t count ; str = ( const nc_utf8proc_uint8_t * ) name ; while ( * str ) { count = nc_utf8proc_iterate ( str , strlen , & codepoint ) ; if ( count < 0 ) { switch ( count ) { case UTF8PROC_ERROR_NOMEM : case UTF8PROC_ERROR_OVERFLOW : ncstat = NC_ENOMEM ; break ; case UTF8PROC_ERROR_INVALIDOPTS : ncstat = NC_EINVAL ; break ; case UTF8PROC_ERROR_INVALIDUTF8 : case UTF8PROC_ERROR_NOTASSIGNED : default : ncstat = NC_EBADNAME ; break ; } goto done ; } else { str += count ; } } done : return ncstat ; }
Check validity of a UTF8 encoded null-terminated byte string.
Check validity of a UTF8 encoded null - terminated byte string .
/* move to next char */