openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/lib/strutils.c
const char* split(const char** state, size_t* l, const char* separator,
                  int quoted)
{
    const char* current;

    current = *state;

    if (!*current)
    {
        assert(**state == '\0');
        return NULL;
    }

    current += strspn(current, separator);
    if (!*current)
    {
        *state = current;
        return NULL;
    }

    if (quoted && strchr("\'\"", *current))
    {
        char quotechars[2] = {*current, '\0'};

        *l = strcspn_escaped(current + 1, quotechars);
        if (current[*l + 1] == '\0' || current[*l + 1] != quotechars[0] ||
            (current[*l + 2] && !strchr(separator, current[*l + 2])))
        {
            /* right quote missing or garbage at the end */
            *state = current;
            return NULL;
        }
        *state = current++ + *l + 2;
    }
    else if (quoted)
    {
        *l = strcspn_escaped(current, separator);
        if (current[*l] && !strchr(separator, current[*l]))
        {
            /* unfinished escape */
            *state = current;
            return NULL;
        }
        *state = current + *l;
    }
    else
    {
        *l = strcspn(current, separator);
        *state = current + *l;
    }

    return current;
}
/* Split a string into words. */
Split a string into words.
Split a string into words .
const char* split(const char** state, size_t* l, const char* separator,
                  int quoted)
{
    const char* current;
    current = *state;
    if (!*current)
    {
        assert(**state == '\0');
        return NULL;
    }
    current += strspn(current, separator);
    if (!*current)
    {
        *state = current;
        return NULL;
    }
    if (quoted && strchr("\'\"", *current))
    {
        char quotechars[2] = {*current, '\0'};
        *l = strcspn_escaped(current + 1, quotechars);
        if (current[*l + 1] == '\0' || current[*l + 1] != quotechars[0] ||
            (current[*l + 2] && !strchr(separator, current[*l + 2])))
        {
            *state = current;
            return NULL;
        }
        *state = current++ + *l + 2;
    }
    else if (quoted)
    {
        *l = strcspn_escaped(current, separator);
        if (current[*l] && !strchr(separator, current[*l]))
        {
            *state = current;
            return NULL;
        }
        *state = current + *l;
    }
    else
    {
        *l = strcspn(current, separator);
        *state = current + *l;
    }
    return current;
}
const char * split ( const char * * state , size_t * l , const char * separator , int quoted ) { const char * current ; current = * state ; if ( ! * current ) { assert ( * * state == ' \0 ' ) ; return NULL ; } current += strspn ( current , separator ) ; if ( ! * current ) { * state = current ; return NULL ; } if ( quoted && strchr ( " \' \" " , * current ) ) { char quotechars [ 2 ] = { * current , ' \0 ' } ; * l = strcspn_escaped ( current + 1 , quotechars ) ; if ( current [ * l + 1 ] == ' \0 ' || current [ * l + 1 ] != quotechars [ 0 ] || ( current [ * l + 2 ] && ! strchr ( separator , current [ * l + 2 ] ) ) ) { * state = current ; return NULL ; } * state = current ++ + * l + 2 ; } else if ( quoted ) { * l = strcspn_escaped ( current , separator ) ; if ( current [ * l ] && ! strchr ( separator , current [ * l ] ) ) { * state = current ; return NULL ; } * state = current + * l ; } else { * l = strcspn ( current , separator ) ; * state = current + * l ; } return current ; }
Split a string into words.
Split a string into words .
/* right quote missing or garbage at the end */ /* unfinished escape */