char* value;
} config_value;
-void trim_whitespace_before(config_value* value)
+void trim_value_whitespace_before(config_value* value)
{
int before = 0;
while(value->value[before] == ' ') {
value->value_length = new_length;
}
+void trim_value_whitespace_after(config_value* value)
+{
+ int after = 0;
+ while(value->value[after] != ' ') {
+ after++;
+ }
+
+ int new_length = after + 1;
+ char* new_value = malloc(sizeof(char) * new_length);
+ memcpy(new_value, value->value, new_length);
+ new_value[new_length - 1] = '\0';
+
+ free(value->value);
+ value->value = NULL;
+ value->value = new_value;
+ value->value_length = new_length;
+}
+
+void trim_value(config_value* value)
+{
+ trim_value_whitespace_before(value);
+ trim_value_whitespace_after(value);
+}
+
void get_line(const char* config_stream, config_line* line)
{
while(config_stream[line->length] != '\n') {
get_line(config_stream, &line);
get_key(&line, &value);
get_value(&line, &value);
- trim_whitespace_before(&value);
+ trim_value(&value);
config->scanner_url = malloc(sizeof(char) * value.value_length);
memcpy(config->scanner_url, value.value, value.value_length);
START_TEST(kds_s2000w_config_read_parameter)
{
- const char* input_stream = "scanner_url = http://scanner.example.com\n";
+ const char* input_stream = "scanner_url = http://scanner.example.com \n";
program_config* config = malloc(sizeof(program_config));
loadConfig(config, input_stream);