Add a string/string mapper struct

This commit is contained in:
Nils O. Selåsdal
2014-02-04 20:51:47 +01:00
parent 39290eefb7
commit 0f25a0f565
3 changed files with 53 additions and 6 deletions
+18 -3
View File
@@ -8,17 +8,23 @@ struct UCValStr {
const char *str;
};
struct UCStrStr {
const char *val;
const char *str;
};
/** Helper macro to define an entry in a UCValStr array */
#define UC_VS_ENTRY(constant) {constant, #constant}
#define UC_VS_TERMINATOR {-1, NULL}
#define UC_SS_TERMINATOR {NULL, NULL}
/** Find @val in @array.
* The last .str in @array must be a NULL pointer.
/** find @val in @array.
* the last .str in @array must be a null pointer.
* (does a linear search)
*
* @param val value to find
* @param array array to search
* @return the string associated with @val or NULL
* @return the string associated with @val or null
*/
const char *uc_val_2_str(unsigned int val, const struct UCValStr *array);
@@ -34,5 +40,14 @@ const char *uc_val_2_str_bs(unsigned int val,
const struct UCValStr *array,
size_t array_len);
/** find @val in @array.
* the last .val in @array must be a null pointer.
* (does a linear search)
*
* @param val value to find, using strcmp
* @param array array to search
* @return the string associated with @val or null
*/
const char *uc_str_2_str(const char *val, const struct UCStrStr *array);
#endif