diff --git a/HISTORY b/HISTORY index 1b4e216..2564596 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ -Version 1.49 2021-03-19 +Version 1.49 2021-03-21 * add macros: FC_ABS and FC_NEGATIVE * uniq_skiplist.c: add uniq_skiplist_pair struct and init function * add functions: fc_mkdirs and str_replace * add FilenameString type and macro + * add functions: fc_string_case_compare, fc_string_case_equal etc. Version 1.48 2021-02-01 * fast_buffer.[hc]: add function fast_buffer_append_binary diff --git a/src/common_define.h b/src/common_define.h index 32a9c71..0e777cd 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -207,6 +207,12 @@ typedef struct int count; } string_array_t; +typedef struct +{ + int64_t id; + string_t name; +} id_name_pair_t; + typedef struct { string_t key; @@ -327,6 +333,39 @@ static inline bool fc_string_equal2(const string_t *s1, #define fc_string_equals(s1, s2) fc_string_equal(s1, s2) #define fc_string_equals2(s1, str2, len2) fc_string_equal2(s1, str2, len2) + +#define fc_case_compare_string(s1, s2) fc_string_case_compare(s1, s2) + +static inline int fc_string_case_compare(const string_t *s1, const string_t *s2) +{ + int result; + if (s1->len == s2->len) { + return strncasecmp(s1->str, s2->str, s1->len); + } else if (s1->len < s2->len) { + result = strncasecmp(s1->str, s2->str, s1->len); + return result == 0 ? -1 : result; + } else { + result = strncasecmp(s1->str, s2->str, s2->len); + return result == 0 ? 1 : result; + } +} + +static inline bool fc_string_case_equal(const string_t *s1, const string_t *s2) +{ + return (s1->len == s2->len) && (strncasecmp(s1->str, s2->str, s1->len) == 0); +} + +static inline bool fc_string_case_equal2(const string_t *s1, + const char *str2, const int len2) +{ + return (s1->len == len2) && (strncasecmp(s1->str, str2, s1->len) == 0); +} + +#define fc_string_case_equals(s1, s2) fc_string_case_equal(s1, s2) +#define fc_string_case_equals2(s1, str2, len2) \ + fc_string_case_equal2(s1, str2, len2) + + static inline int fc_compare_int64(const int64_t n1, const int64_t n2) { int64_t sub;