Project

General

Profile

Feature #12786 ยป string_casecmp_.patch

rringler (Ryan Ringler), 09/24/2016 03:55 AM

View differences:

string.c
return INT2FIX(-1);
}
/*
* call-seq:
* str.casecmp?(other_str) -> true or false
*
* Case-insensitive string comparison.
*
* "abcdef".casecmp?("abcde") #=> false
* "aBcDeF".casecmp?("abcdef") #=> true
* "abcdef".casecmp?("abcdefg") #=> false
* "abcdef".casecmp?("ABCDEF") #=> true
*/
static VALUE
rb_str_casecmp_p(VALUE str1, VALUE str2)
{
return rb_str_casecmp(str1, str2) == INT2FIX(0) ? Qtrue : Qfalse;
}
#define rb_str_index(str, sub, offset) rb_strseq_index(str, sub, offset, 0)
static long
......
}
/*
* call-seq:
* sym.casecmp?(other) -> true, false, or nil
*
* Case-insensitive symbol comparison.
*/
static VALUE
sym_casecmp_p(VALUE sym, VALUE other)
{
if (!SYMBOL_P(other)) {
return Qnil;
}
return sym_casecmp(sym, other) == INT2FIX(0) ? Qtrue : Qfalse;
}
/*
* call-seq:
* sym =~ obj -> integer or nil
*
......
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, "casecmp?", rb_str_casecmp_p, 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_m, 1);
......
rb_define_method(rb_cSymbol, "<=>", sym_cmp, 1);
rb_define_method(rb_cSymbol, "casecmp", sym_casecmp, 1);
rb_define_method(rb_cSymbol, "casecmp?", sym_casecmp_p, 1);
rb_define_method(rb_cSymbol, "=~", sym_match, 1);
rb_define_method(rb_cSymbol, "[]", sym_aref, -1);
test/ruby/enc/test_utf16.rb
assert_not_equal(0, s1.casecmp(s2), "#{encdump s1}.casecmp(#{encdump s2})")
end
def test_casecmp?
s1 = "aa".force_encoding("utf-16be")
s2 = "AA"
assert_not_equal(true, s1.casecmp?(s2), "#{encdump s1}.casecmp?(#{encdump s2})")
end
def test_end_with
s1 = "ab".force_encoding("utf-16be")
s2 = "b".force_encoding("utf-16be")
......
a = ary.sort {|x,y| x.casecmp(y) }
assert_equal(e, a)
end
def test_casecmp2?
assert_equal(true, "\0A".force_encoding("UTF-16BE").casecmp?("\0a".force_encoding("UTF-16BE")))
assert_not_equal(true, "\0A".force_encoding("UTF-16LE").casecmp?("\0a".force_encoding("UTF-16LE")))
assert_not_equal(true, "A\0".force_encoding("UTF-16BE").casecmp?("a\0".force_encoding("UTF-16BE")))
assert_equal(true, "A\0".force_encoding("UTF-16LE").casecmp?("a\0".force_encoding("UTF-16LE")))
end
end
test/ruby/test_m17n.rb
assert_not_equal(0, s1.casecmp(s2))
end
def test_casecmp?
s1 = s("\x81\x41")
s2 = s("\x81\x61")
assert_not_equal(true, s1.casecmp?(s2))
end
def test_reverse
bug11387 = '[ruby-dev:49189] [Bug #11387]'
s1 = u("abcdefghij\xf0")
test/ruby/test_m17n_comb.rb
}
end
def test_str_casecmp?
combination(STRINGS, STRINGS) {|s1, s2|
next unless s1.valid_encoding? && s2.valid_encoding? && Encoding.compatible?(s1, s2)
r = s1.casecmp?(s2)
assert_equal(s1.casecmp(s2) == 0, r)
}
end
def test_str_center
combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.center(width)
test/ruby/test_string.rb
assert_equal(1, "\u3042B".casecmp("\u3042a"))
end
def test_casecmp?
assert_equal(false, "\u3042B".casecmp?("\u3042a"))
end
def test_upcase2
assert_equal("\u3042AB", "\u3042aB".upcase)
end
test/ruby/test_symbol.rb
assert_nil(:foo.casecmp("foo"))
end
def test_casecmp?
assert_equal(true, :FoO.casecmp?(:fOO))
assert_equal(false, :FoO.casecmp?(:BaR))
assert_equal(false, :baR.casecmp?(:FoO))
assert_nil(:foo.casecmp?("foo"))
end
def test_length
assert_equal(3, :FoO.length)
assert_equal(3, :FoO.size)
    (1-1/1)