src/lq-collections.c
/**
 *  \brief Parses a HTTP style query string (key\value pairs) and creates a dictionary overlay for the keys and values. 
 * 
 *  \param dictSrc [in] - Char pointer to the c-string containing key value pairs to identify. NOTE: the source is mutated in the process, keys\values are NULL term'd.
 *  \param qsSize [in] - Lenght of the incoming query string. 
 * 
 *  \return Struct with map (pointers) to the keys and values (within the source array)
*/
\brief Parses a HTTP style query string (key\value pairs) and creates a dictionary overlay for the keys and values.

\param dictSrc [in] - Char pointer to the c-string containing key value pairs to identify. NOTE: the source is mutated in the process, keys\values are NULL term'd.
\param qsSize [in] - Lenght of the incoming query string.

\return Struct with map (pointers) to the keys and values (within the source array)
\ brief Parses a HTTP style query string ( key \ value pairs ) and creates a dictionary overlay for the keys and values . \ param dictSrc [ in ] - Char pointer to the c - string containing key value pairs to identify . NOTE : the source is mutated in the process keys \ values are NULL term ' d . \ param qsSize [ in ] - Lenght of the incoming query string . \ return Struct with map ( pointers ) to the keys and values ( within the source array )
keyValueDict_t lq_createQryStrDictionary(char *dictSrc, size_t qsSize)
{
    keyValueDict_t result = {0};
    if (qsSize == 0)
        return result;
    result.length = qsSize;
    char *next = dictSrc;
    char *delimAt;
    char *endAt = dictSrc + result.length;
    for (size_t i = 0; i < lqCollections__maxKeyValueDictCnt; i++)          
    {
        delimAt = memchr(dictSrc, '&', endAt - dictSrc);
        delimAt = (delimAt == NULL) ? endAt : delimAt;
        result.keys[i] = dictSrc;
        *delimAt = '\0';
        dictSrc = delimAt + 1;
        result.count = i;
        if (delimAt == endAt)
            break;
    }
    result.count++;
    for (size_t i = 0; i < result.count; i++)                               
    {
        delimAt = memchr(result.keys[i], '=', endAt - result.keys[i]);
        if (delimAt == NULL)
        {
            result.count = i;
            break;
        }
        *delimAt = '\0';
        result.values[i] = delimAt + 1;
    }
    return result;
}
keyValueDict_t lq_createQryStrDictionary ( char * dictSrc , size_t qsSize ) { keyValueDict_t result = { 0 } ; if ( qsSize == 0 ) return result ; result . length = qsSize ; char * next = dictSrc ; char * delimAt ; char * endAt = dictSrc + result . length ; for ( size_t i = 0 ; i < lqCollections__maxKeyValueDictCnt ; i ++ ) { delimAt = memchr ( dictSrc , ' ' , endAt - dictSrc ) ; delimAt = ( delimAt == NULL ) ? endAt : delimAt ; result . keys [ i ] = dictSrc ; * delimAt = ' \0 ' ; dictSrc = delimAt + 1 ; result . count = i ; if ( delimAt == endAt ) break ; } result . count ++ ; for ( size_t i = 0 ; i < result . count ; i ++ ) { delimAt = memchr ( result . keys [ i ] , ' ' , endAt - result . keys [ i ] ) ; if ( delimAt == NULL ) { result . count = i ; break ; } * delimAt = ' \0 ' ; result . values [ i ] = delimAt + 1 ; } return result ; }
\brief Parses a HTTP style query string (key\value pairs) and creates a dictionary overlay for the keys and values.
\ brief Parses a HTTP style query string ( key \ value pairs ) and creates a dictionary overlay for the keys and values .
//keyValueDict_t result = {0, 0, {0}, {0}}; // 1st pass; get names + values // 2nd pass; split names/values