Sfoglia il codice sorgente

libobs/util: Add config_remove_value function

jp9000 10 anni fa
parent
commit
6bf2be407b
2 ha cambiato i file con 32 aggiunte e 0 eliminazioni
  1. 29 0
      libobs/util/config-file.c
  2. 3 0
      libobs/util/config-file.h

+ 29 - 0
libobs/util/config-file.c

@@ -609,6 +609,35 @@ double config_get_double(const config_t *config, const char *section,
 	return 0.0;
 }
 
+bool config_remove_value(config_t *config, const char *section,
+		const char *name)
+{
+	struct darray *sections = &config->sections;
+
+	for (size_t i = 0; i < sections->num; i++) {
+		struct config_section *sec = darray_item(
+				sizeof(struct config_section), sections, i);
+
+		if (astrcmpi(sec->name, section) != 0)
+			continue;
+
+		for (size_t j = 0; j < sec->items.num; j++) {
+			struct config_item *item = darray_item(
+					sizeof(struct config_item),
+					&sec->items, j);
+
+			if (astrcmpi(item->name, name) == 0) {
+				config_item_free(item);
+				darray_erase(sizeof(struct config_item),
+						&sec->items, j);
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
 const char *config_get_default_string(const config_t *config,
 		const char *section, const char *name)
 {

+ 3 - 0
libobs/util/config-file.h

@@ -73,6 +73,9 @@ EXPORT bool config_get_bool(const config_t *config, const char *section,
 EXPORT double config_get_double(const config_t *config, const char *section,
 		const char *name);
 
+EXPORT bool config_remove_value(config_t *config, const char *section,
+		const char *name);
+
 /*
  * DEFAULT VALUES
  *