openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/systemd/1_242+AUTOINC+db2e367bfc-r0/git/src/basic/utf8.c
int utf8_encoded_valid_unichar(const char* str, size_t length /* bytes */)
{
    char32_t unichar;
    size_t len, i;
    int r;

    assert(str);
    assert(length > 0);

    /* We read until NUL, at most length bytes. (size_t) -1 may be used to
     * disable the length check. */

    len = utf8_encoded_expected_len(str[0]);
    if (len == 0)
        return -EINVAL;

    /* Do we have a truncated multi-byte character? */
    if (len > length)
        return -EINVAL;

    /* ascii is valid */
    if (len == 1)
        return 1;

    /* check if expected encoded chars are available */
    for (i = 0; i < len; i++)
        if ((str[i] & 0x80) != 0x80)
            return -EINVAL;

    r = utf8_encoded_to_unichar(str, &unichar);
    if (r < 0)
        return r;

    /* check if encoded length matches encoded value */
    if (utf8_unichar_to_encoded_len(unichar) != (int)len)
        return -EINVAL;

    /* check if value has valid range */
    if (!unichar_is_valid(unichar))
        return -EINVAL;

    return (int)len;
}
/* validate one encoded unicode char and return its length */
validate one encoded unicode char and return its length
validate one encoded unicode char and return its length
int utf8_encoded_valid_unichar(const char* str, size_t length )
{
    char32_t unichar;
    size_t len, i;
    int r;
    assert(str);
    assert(length > 0);
    len = utf8_encoded_expected_len(str[0]);
    if (len == 0)
        return -EINVAL;
    if (len > length)
        return -EINVAL;
    if (len == 1)
        return 1;
    for (i = 0; i < len; i++)
        if ((str[i] & 0x80) != 0x80)
            return -EINVAL;
    r = utf8_encoded_to_unichar(str, &unichar);
    if (r < 0)
        return r;
    if (utf8_unichar_to_encoded_len(unichar) != (int)len)
        return -EINVAL;
    if (!unichar_is_valid(unichar))
        return -EINVAL;
    return (int)len;
}
int utf8_encoded_valid_unichar ( const char * str , size_t length ) { char32_t unichar ; size_t len , i ; int r ; assert ( str ) ; assert ( length > 0 ) ; len = utf8_encoded_expected_len ( str [ 0 ] ) ; if ( len == 0 ) return - EINVAL ; if ( len > length ) return - EINVAL ; if ( len == 1 ) return 1 ; for ( i = 0 ; i < len ; i ++ ) if ( ( str [ i ] & 0x80 ) != 0x80 ) return - EINVAL ; r = utf8_encoded_to_unichar ( str , & unichar ) ; if ( r < 0 ) return r ; if ( utf8_unichar_to_encoded_len ( unichar ) != ( int ) len ) return - EINVAL ; if ( ! unichar_is_valid ( unichar ) ) return - EINVAL ; return ( int ) len ; }
validate one encoded unicode char and return its length
validate one encoded unicode char and return its length
/* bytes */ /* We read until NUL, at most length bytes. (size_t) -1 may be used to
     * disable the length check. */ /* Do we have a truncated multi-byte character? */ /* ascii is valid */ /* check if expected encoded chars are available */ /* check if encoded length matches encoded value */ /* check if value has valid range */