src/core/config/parser.c
/**
 * Take a value string which we know contains an array and return a string
 * containing all of the array value items.
 *
 * We allow arrays to span multiple lines so this function has to take that
 * into account and reparse the value string if we don't find an ARRAY_END
 * character at the end of the passed string
 *
 * The parser position is kept up to date in the case of a multiline value
 */
Take a value string which we know contains an array and return a string
containing all of the array value items.

We allow arrays to span multiple lines so this function has to take that
into account and reparse the value string if we don't find an ARRAY_END
character at the end of the passed string

The parser position is kept up to date in the case of a multiline value
Take a value string which we know contains an array and return a string containing all of the array value items . We allow arrays to span multiple lines so this function has to take that into account and reparse the value string if we don ' t find an ARRAY_END character at the end of the passed string The parser position is kept up to date in the case of a multiline value
static enum natwm_error array_find_value_items_string(struct parser *parser, char *string,
                                                      char **result, size_t *length)
{
        char *array_value_string = NULL;
        if (char_to_token(string[strlen(string) - 1]) != ARRAY_END) {
                size_t end_pos = 0;
                const char *line = parser->buffer + parser->pos;
                enum natwm_error err = get_array_string(line, &array_value_string, &end_pos);
                if (err != NO_ERROR) {
                        LOG_ERROR(natwm_logger,
                                  "Could not find ']' in array value string - "
                                  "Line %zu",
                                  parser->line_num);
                        return INVALID_INPUT_ERROR;
                }
                parser_move(parser, end_pos);
        } else {
                array_value_string = string_init(string);
        }
        char *array_value_items_string = NULL;
        size_t array_value_items_string_size = 0;
        enum natwm_error err = string_splice(array_value_string,
                                             1,
                                             strlen(array_value_string) - 1,
                                             &array_value_items_string,
                                             &array_value_items_string_size);
        if (err != NO_ERROR) {
                free(array_value_string);
                return err;
        }
        free(array_value_string);
        *result = array_value_items_string;
        *length = array_value_items_string_size;
        return NO_ERROR;
}
static enum natwm_error array_find_value_items_string ( struct parser * parser , char * string , char * * result , size_t * length ) { char * array_value_string = NULL ; if ( char_to_token ( string [ strlen ( string ) - 1 ] ) != ARRAY_END ) { size_t end_pos = 0 ; const char * line = parser -> buffer + parser -> pos ; enum natwm_error err = get_array_string ( line , & array_value_string , & end_pos ) ; if ( err != NO_ERROR ) { LOG_ERROR ( natwm_logger , " " " " , parser -> line_num ) ; return INVALID_INPUT_ERROR ; } parser_move ( parser , end_pos ) ; } else { array_value_string = string_init ( string ) ; } char * array_value_items_string = NULL ; size_t array_value_items_string_size = 0 ; enum natwm_error err = string_splice ( array_value_string , 1 , strlen ( array_value_string ) - 1 , & array_value_items_string , & array_value_items_string_size ) ; if ( err != NO_ERROR ) { free ( array_value_string ) ; return err ; } free ( array_value_string ) ; * result = array_value_items_string ; * length = array_value_items_string_size ; return NO_ERROR ; }
Take a value string which we know contains an array and return a string
 containing all of the array value items.
Take a value string which we know contains an array and return a string containing all of the array value items .
// An array value string in the format // [<value>,<value>] // We found a valid multiline array value string. But now we // need to update the parser position to point to the end of the // array value string // Our array exists on a single line // From our value string we need to get the array items list // <value>,<value>