Project

General

Profile

Actions

Feature #14055

closed

String#casecmp should use Unicode folding

Added by rbjl (Jan Lelis) about 7 years ago. Updated about 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:83566]

Description

The following string and symbol methods are currently only ASCII aware:

  • String#casecmp
  • String#casecmp!
  • Symbol#casecmp
  • Symbol#casecmp!

For example:

"a".casecmp("A") #=> 0
"ä".casecmp("Ä") #=> 1

Now that Ruby has implemented case-folding (which is meant for comparing strings, see http://unicode.org/faq/casemap_charprop.html#2), it should be used when doing a casecmp on Unicode strings:

"Ä".downcase(:fold) == "ä" #=> true

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12786: String#casecmp?Closedduerst (Martin Dürst)Actions

Updated by shyouhei (Shyouhei Urabe) about 7 years ago

  • Status changed from Open to Rejected

Yes, we have unicode-aware case folding. But the problem is, because String#casecmp returns either -1, 0, or 1, we need to define a total ordering of strings in case-insensitive manner. It's pretty difficult (if not impossible).

If you are not interested in sorting strings but only for comparison, you can use String#casecmp? method (note the "?"). See also: https://bugs.ruby-lang.org/issues/12786

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

Updated by rbjl (Jan Lelis) about 7 years ago

Thanks for the pointer!

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0