Add a few more UCStrVal functions

This commit is contained in:
Nils O. Selåsdal
2014-09-10 23:55:33 +02:00
parent 48563f553d
commit eacdd947e5
3 changed files with 83 additions and 2 deletions
+31
View File
@@ -19,6 +19,21 @@ const char *uc_val_2_str(unsigned int val, const struct UCValStr *array)
return found;
}
const struct UCValStr *uc_val_2_str_vs(unsigned int val, const struct UCValStr *array)
{
const struct UCValStr *found = NULL;
while (array->str) {
if (array->val == val) {
found = array;
break;
}
array++;
}
return found;
}
const char *uc_val_2_str_bs(unsigned int val,
const struct UCValStr *array,
size_t array_len)
@@ -62,3 +77,19 @@ const char *uc_str_2_str(const char *restrict val, const struct UCStrStr *array)
return found;
}
const char *uc_str_2_str_ci(const char *restrict val, const struct UCStrStr *array)
{
const char *found = NULL;
while (array->val) {
if (strcasecmp(val, array->val) == 0) {
found = array->str;
break;
}
array++;
}
return found;
}