Util: Adding a null value to a Configuration removes the value

This commit is contained in:
Jeffrey Pfau 2014-11-04 23:47:31 -08:00
parent 75557d11b2
commit 11bf4fdfda
1 changed files with 6 additions and 2 deletions

View File

@ -40,13 +40,17 @@ void ConfigurationSetValue(struct Configuration* configuration, const char* sect
struct Table* currentSection = &configuration->root;
if (section) {
currentSection = HashTableLookup(&configuration->sections, section);
if (!currentSection) {
if (!currentSection && value) {
currentSection = malloc(sizeof(*currentSection));
HashTableInit(currentSection, 0, _sectionDeinit);
HashTableInsert(&configuration->sections, section, currentSection);
}
}
HashTableInsert(currentSection, key, strdup(value));
if (value) {
HashTableInsert(currentSection, key, strdup(value));
} else {
HashTableRemove(currentSection, key);
}
}
const char* ConfigurationGetValue(const struct Configuration* configuration, const char* section, const char* key) {