#include #include #include "ucore/val_str.h" const char *uc_val_2_str(unsigned int val, const struct UCValStr *array) { const char *found = NULL; while (array->str) { if (array->val == val) { found = array->str; break; } 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) { size_t i = array_len; const struct UCValStr *start = array; const char *found = NULL; while (i != 0) { const struct UCValStr *curr; curr = &start[i / 2]; //middle if (curr->val == val) { found = curr->str; break; } if (curr->val < val) { start = curr + 1; //right half i--; } i = i / 2; } return found; } const char *uc_str_2_str(const char *restrict val, const struct UCStrStr *array) { const char *found = NULL; while (array->val) { if (strcmp(val, array->val) == 0) { found = array->str; break; } 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; }