string.c: add mrb_strcasecmp_p for case-insensitive comparison

Move casecmp_p from mruby-string-ext and mruby-encoding to core as
mrb_strcasecmp_p (predicate function returning mrb_bool). Add
MRB_STR_CASECMP_P macro to internal.h for comparing mrb_value strings
with literal strings.

This eliminates code duplication and avoids static function name
collision for future amalgamation support.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-23 10:41:21 +09:00
parent ce570c28bb
commit 768a1f7752
4 changed files with 23 additions and 42 deletions
+14
View File
@@ -50,6 +50,20 @@ str_check_length(mrb_state *mrb, mrb_int len)
#endif
}
mrb_bool
mrb_strcasecmp_p(const char *s1, mrb_int len1, const char *s2, mrb_int len2)
{
if (len1 != len2) return FALSE;
const char *e1 = s1 + len1;
while (s1 < e1) {
if (*s1 != *s2 && TOUPPER(*s1) != TOUPPER(*s2)) return FALSE;
s1++;
s2++;
}
return TRUE;
}
static struct RString*
str_init_normal_capa(mrb_state *mrb, struct RString *s,
const char *p, mrb_int len, mrb_int capa)