diff options
Diffstat (limited to 'ext/unicorn_http/ext_help.h')
-rw-r--r-- | ext/unicorn_http/ext_help.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/unicorn_http/ext_help.h b/ext/unicorn_http/ext_help.h index 19f08c9..5f7c296 100644 --- a/ext/unicorn_http/ext_help.h +++ b/ext/unicorn_http/ext_help.h @@ -26,4 +26,23 @@ static inline int str_cstr_eq(VALUE val, const char *ptr, size_t len) #define STR_CSTR_EQ(val, const_str) \ str_cstr_eq(val, const_str, sizeof(const_str) - 1) +/* strcasecmp isn't locale independent */ +static int str_cstr_case_eq(VALUE val, const char *ptr, size_t len) +{ + if (RSTRING_LEN(val) == len) { + const char *v = RSTRING_PTR(val); + + for (; len--; ++ptr, ++v) { + if ((*ptr == *v) || (*v >= 'A' && *v <= 'Z' && (*v | 0x20) == *ptr)) + continue; + return 0; + } + return 1; + } + return 0; +} + +#define STR_CSTR_CASE_EQ(val, const_str) \ + str_cstr_case_eq(val, const_str, sizeof(const_str) - 1) + #endif |