diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-30 12:02:21 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-01 07:00:54 +0900 |
| commit | 37a7ff228b4b8b5c0230ef5a80ba1312763d93f8 (patch) | |
| tree | bbb7254053b2b0c57a28b7fc2d42b5c328547445 /mrbgems/mruby-string-ext/mrblib/string.rb | |
| parent | f6e5c902f0591e32088623d6ed4146e34f58fd85 (diff) | |
| download | mruby-37a7ff228b4b8b5c0230ef5a80ba1312763d93f8.tar.gz mruby-37a7ff228b4b8b5c0230ef5a80ba1312763d93f8.zip | |
string-ext/string.c: implement `casecmp` in C.
* should not raise error for non-string arguments
* avoid allocating case converted string internally
Diffstat (limited to 'mrbgems/mruby-string-ext/mrblib/string.rb')
| -rw-r--r-- | mrbgems/mruby-string-ext/mrblib/string.rb | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb index 2b3071567..d485c51ef 100644 --- a/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -111,36 +111,6 @@ class String (s == self) ? nil : self.replace(s) end - ## - # call-seq: - # str.casecmp(other_str) -> -1, 0, +1 or nil - # - # Case-insensitive version of <code>String#<=></code>. - # - # "abcdef".casecmp("abcde") #=> 1 - # "aBcDeF".casecmp("abcdef") #=> 0 - # "abcdef".casecmp("abcdefg") #=> -1 - # "abcdef".casecmp("ABCDEF") #=> 0 - # - def casecmp(str) - self.downcase <=> str.__to_str.downcase - rescue NoMethodError - nil - end - - ## - # call-seq: - # str.casecmp?(other) -> true, false, or nil - # - # Returns true if str and other_str are equal after case folding, - # false if they are not equal, and nil if other_str is not a string. - - def casecmp?(str) - c = self.casecmp(str) - return nil if c.nil? - return c == 0 - end - def partition(sep) raise TypeError, "type mismatch: #{sep.class} given" unless sep.is_a? String n = index(sep) |
