#ifndef UC_VAL_STR_H_ #define UC_VAL_STR_H_ #include struct UCValStr { unsigned int val; const char *str; }; #define UC_VS_ENTRY(constant) {constant, #constant} #define UC_VS_TERMINATOR {-1, NULL} /** 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 */ const char *uc_vs_search(unsigned int val, const struct UCValStr *array); /** Find @val in @array. * @array must be sorted on val and must not be empty * (does a binary search) * * @param val value to find * @param array array to search * @return the string associated with @val or NULL */ const char *uc_vs_bsearch(unsigned int val, const struct UCValStr *array, size_t array_len); #endif