src/core/config/parser.c
/**
 * Read a value from the parser buffer
 *
 * The parser buffer will be pointing to the beginning of a string something
 * like this:
 *
 * = <value>
 *
 * We will need to ignore the EQUAL_CHAR and stripped the spaces around the
 * value. We will then return the string back to the caller who can deal with
 * turning it into a config_value
 */
Read a value from the parser buffer
The parser buffer will be pointing to the beginning of a string something
like this.



We will need to ignore the EQUAL_CHAR and stripped the spaces around the
value. We will then return the string back to the caller who can deal with
turning it into a config_value
Read a value from the parser buffer The parser buffer will be pointing to the beginning of a string something like this . We will need to ignore the EQUAL_CHAR and stripped the spaces around the value . We will then return the string back to the caller who can deal with turning it into a config_value
enum natwm_error parser_read_value(struct parser *parser, char **result, size_t *length)
{
        enum natwm_error err = GENERIC_ERROR;
        const char *line = (parser->buffer + parser->pos) + 1;
        char *value = NULL;
        size_t end_pos = 0;
        err = string_get_delimiter(line, '\n', &value, &end_pos, false);
        if (err != NO_ERROR) {
                LOG_ERROR(natwm_logger,
                          "Failed to read item value - Line %zu Col: %zu",
                          parser->line_num,
                          parser->col_num);
                return INVALID_INPUT_ERROR;
        }
        char *value_stripped = NULL;
        size_t value_stripped_length = 0;
        err = string_strip_surrounding_spaces(value, &value_stripped, &value_stripped_length);
        if (err != NO_ERROR) {
                LOG_ERROR(natwm_logger,
                          "Found invalid item value - Line %zu Col: %zu",
                          parser->line_num,
                          parser->col_num);
                free(value);
                return INVALID_INPUT_ERROR;
        }
        free(value);
        parser_move(parser, end_pos);
        *result = value_stripped;
        SET_IF_NON_NULL(length, value_stripped_length);
        return NO_ERROR;
}
enum natwm_error parser_read_value ( struct parser * parser , char * * result , size_t * length ) { enum natwm_error err = GENERIC_ERROR ; const char * line = ( parser -> buffer + parser -> pos ) + 1 ; char * value = NULL ; size_t end_pos = 0 ; err = string_get_delimiter ( line , ' \n ' , & value , & end_pos , false ) ; if ( err != NO_ERROR ) { LOG_ERROR ( natwm_logger , " " , parser -> line_num , parser -> col_num ) ; return INVALID_INPUT_ERROR ; } char * value_stripped = NULL ; size_t value_stripped_length = 0 ; err = string_strip_surrounding_spaces ( value , & value_stripped , & value_stripped_length ) ; if ( err != NO_ERROR ) { LOG_ERROR ( natwm_logger , " " , parser -> line_num , parser -> col_num ) ; free ( value ) ; return INVALID_INPUT_ERROR ; } free ( value ) ; parser_move ( parser , end_pos ) ; * result = value_stripped ; SET_IF_NON_NULL ( length , value_stripped_length ) ; return NO_ERROR ; }
Read a value from the parser buffer
 The parser buffer will be pointing to the beginning of a string something
 like this:
Read a value from the parser buffer The parser buffer will be pointing to the beginning of a string something like this :
// We need to ignore the EQUAL_CHAR // Now we need to strip the surrounding spaces to be left with the value // string // Free intermediate values // Update the parser position to the end of the line