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/libudev/libudev-util.c
size_t util_replace_chars(char* str, const char* white)
{
    size_t i = 0, replaced = 0;

    assert(str);

    while (str[i] != '\0')
    {
        int len;

        if (whitelisted_char_for_devnode(str[i], white))
        {
            i++;
            continue;
        }

        /* accept hex encoding */
        if (str[i] == '\\' && str[i + 1] == 'x')
        {
            i += 2;
            continue;
        }

        /* accept valid utf8 */
        len = utf8_encoded_valid_unichar(str + i, (size_t)-1);
        if (len > 1)
        {
            i += len;
            continue;
        }

        /* if space is allowed, replace whitespace with ordinary space */
        if (isspace(str[i]) && white && strchr(white, ' '))
        {
            str[i] = ' ';
            i++;
            replaced++;
            continue;
        }

        /* everything else is replaced with '_' */
        str[i] = '_';
        i++;
        replaced++;
    }
    return replaced;
}
/* allow chars in whitelist, plain ascii, hex-escaping and valid utf8 */
allow chars in whitelist, plain ascii, hex-escaping and valid utf8
allow chars in whitelist plain ascii hex - escaping and valid utf8
size_t util_replace_chars(char* str, const char* white)
{
    size_t i = 0, replaced = 0;
    assert(str);
    while (str[i] != '\0')
    {
        int len;
        if (whitelisted_char_for_devnode(str[i], white))
        {
            i++;
            continue;
        }
        if (str[i] == '\\' && str[i + 1] == 'x')
        {
            i += 2;
            continue;
        }
        len = utf8_encoded_valid_unichar(str + i, (size_t)-1);
        if (len > 1)
        {
            i += len;
            continue;
        }
        if (isspace(str[i]) && white && strchr(white, ' '))
        {
            str[i] = ' ';
            i++;
            replaced++;
            continue;
        }
        str[i] = '_';
        i++;
        replaced++;
    }
    return replaced;
}
size_t util_replace_chars ( char * str , const char * white ) { size_t i = 0 , replaced = 0 ; assert ( str ) ; while ( str [ i ] != ' \0 ' ) { int len ; if ( whitelisted_char_for_devnode ( str [ i ] , white ) ) { i ++ ; continue ; } if ( str [ i ] == ' \\ ' && str [ i + 1 ] == ' ' ) { i += 2 ; continue ; } len = utf8_encoded_valid_unichar ( str + i , ( size_t ) -1 ) ; if ( len > 1 ) { i += len ; continue ; } if ( isspace ( str [ i ] ) && white && strchr ( white , ' ' ) ) { str [ i ] = ' ' ; i ++ ; replaced ++ ; continue ; } str [ i ] = ' ' ; i ++ ; replaced ++ ; } return replaced ; }
allow chars in whitelist, plain ascii, hex-escaping and valid utf8
allow chars in whitelist plain ascii hex - escaping and valid utf8
/* accept hex encoding */ /* accept valid utf8 */ /* if space is allowed, replace whitespace with ordinary space */ /* everything else is replaced with '_' */