mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: create taxonomy_get_value() function
This is the counter-part to taxonomy_set_value(). Let taxonomy_get_country() be the first user of the function. If a category doesn't exist, return NULL. Small addition: make taxonomy_get_countr() take a const argument. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e5923a105a
commit
1f1fd78f78
2 changed files with 10 additions and 7 deletions
|
@ -72,13 +72,15 @@ int taxonomy_index_for_category(const struct taxonomy_data *t, enum taxonomy_cat
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char *taxonomy_get_country(struct taxonomy_data *t)
|
||||
const char *taxonomy_get_value(const struct taxonomy_data *t, enum taxonomy_category cat)
|
||||
{
|
||||
for (int i = 0; i < t->nr; i++) {
|
||||
if (t->category[i].category == TC_COUNTRY)
|
||||
return t->category[i].value;
|
||||
}
|
||||
return NULL;
|
||||
int idx = taxonomy_index_for_category(t, cat);
|
||||
return idx >= 0 ? t->category[idx].value : NULL;
|
||||
}
|
||||
|
||||
const char *taxonomy_get_country(const struct taxonomy_data *t)
|
||||
{
|
||||
return taxonomy_get_value(t, TC_COUNTRY);
|
||||
}
|
||||
|
||||
void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category category, const char *value, enum taxonomy_origin origin)
|
||||
|
|
|
@ -42,7 +42,8 @@ struct taxonomy_data {
|
|||
void free_taxonomy(struct taxonomy_data *t);
|
||||
void copy_taxonomy(const struct taxonomy_data *orig, struct taxonomy_data *copy);
|
||||
int taxonomy_index_for_category(const struct taxonomy_data *t, enum taxonomy_category cat);
|
||||
const char *taxonomy_get_country(struct taxonomy_data *t);
|
||||
const char *taxonomy_get_value(const struct taxonomy_data *t, enum taxonomy_category cat);
|
||||
const char *taxonomy_get_country(const struct taxonomy_data *t);
|
||||
void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category category, const char *value, enum taxonomy_origin origin);
|
||||
void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum taxonomy_origin origin);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue