diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-07-24 09:07:33 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-07-24 09:07:33 +0000 |
commit | 15ffbb1f820be7c798a7eb0aa2be11b5d4207460 (patch) | |
tree | f27d9d12e2cda0dca1435e1f0567d9fb423c7230 /string.c | |
parent | 9e214f30c4f2bb6e6529c1bb988be1e46026919f (diff) |
* eval.c (rb_provide_feature): should not tweak extension used for
loading.
* io.c (io_fread): use fread(3) if PENDING_COUND is available.
* class.c (rb_mod_include_p): Module#include? added. [new]
* re.c (ignorecase_setter): give warning on modifying $=.
* string.c (rb_str_casecmp): new method. [new]
* string.c (rb_str_eql): separated from rb_str_equal(), make it
always be case sensitive. [new]
* string.c (rb_str_hash): made it always be case sensitive.
* eval.c (rb_f_require): should not include path in $" value
* file.c (rb_find_file): should return 0 explicitly on failure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 63 |
1 files changed, 41 insertions, 22 deletions
@@ -639,30 +639,14 @@ rb_str_hash(str) key &= ~g; } #elif HASH_PERL - if (ruby_ignorecase) { - while (len--) { - key = key*33 + toupper(*p); - p++; - } - } - else { - while (len--) { - key = key*33 + *p++; - } + while (len--) { + key = key*33 + *p++; } key = key + (key>>5); #else - if (ruby_ignorecase) { - while (len--) { - key = key*65599 + toupper(*p); - p++; - } - } - else { - while (len--) { - key = key*65599 + *p; - p++; - } + while (len--) { + key = key*65599 + *p; + p++; } key = key + (key>>5); #endif @@ -713,6 +697,20 @@ rb_str_equal(str1, str2) } static VALUE +rb_str_eql(str1, str2) + VALUE str1, str2; +{ + if (TYPE(str2) != T_STRING || RSTRING(str1)->len != RSTRING(str2)->len) + return Qfalse; + + if (memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, + lesser(RSTRING(str1)->len, RSTRING(str2)->len)) == 0) + return Qtrue; + + return Qfalse; +} + +static VALUE rb_str_cmp_m(str1, str2) VALUE str1, str2; { @@ -724,6 +722,26 @@ rb_str_cmp_m(str1, str2) } 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); +} + +static VALUE rb_str_match(x, y) VALUE x, y; { @@ -2934,8 +2952,9 @@ Init_String() rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1); rb_define_method(rb_cString, "==", rb_str_equal, 1); rb_define_method(rb_cString, "===", rb_str_equal, 1); - rb_define_method(rb_cString, "eql?", rb_str_equal, 1); + rb_define_method(rb_cString, "eql?", rb_str_eql, 1); rb_define_method(rb_cString, "hash", rb_str_hash_m, 0); + rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1); rb_define_method(rb_cString, "+", rb_str_plus, 1); rb_define_method(rb_cString, "*", rb_str_times, 1); rb_define_method(rb_cString, "%", rb_str_format, 1); |