casecmp(p1)
public
Case-insensitive version of String#<=>.
"abcdef".casecmp("abcde")
"aBcDeF".casecmp("abcdef")
"abcdef".casecmp("abcdefg")
"abcdef".casecmp("ABCDEF")
Show source
/*
* call-seq:
* str.casecmp(other_str) => -1, 0, +1
*
* Case-insensitive version of <code>String#<=></code>.
*
* "abcdef".casecmp("abcde")
* "aBcDeF".casecmp("abcdef")
* "abcdef".casecmp("abcdefg")
* "abcdef".casecmp("ABCDEF")
*/
static VALUE
rb_str_casecmp(str1, str2)
VALUE str1, str2;
{
long len;
int retval;
StringValue(str2);
len = lesser(RSTRING(str1)->len, RSTRING(str2)->len);
retval = rb_memcicmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len);
if (retval == 0) {
if (RSTRING(str1)->len == RSTRING(str2)->len) return INT2FIX(0);
if (RSTRING(str1)->len > RSTRING(str2)->len) return INT2FIX(1);
return INT2FIX(-1);
}
if (retval == 0) return INT2FIX(0);
if (retval > 0) return INT2FIX(1);
return INT2FIX(-1);
}