# String#upcase/downcase with UTF-8 strings in Ruby 1.9

**URL:** <https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639>\
**Category:** Ruby\
**Created:** [July 10, 2008, 12:14am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639 "2008-07-10T00:14:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 12:14am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/1 "2008-07-10T00:14:15Z")

</div>

Hello,

in Ruby 1.9 I get the following behaviour:

> > “aoueäöüé”.upcase  
> > =\>  
> > “AOUEäöüé”\>\> “AOUEÄÖÜÉ”.downcase  
> > =\> “aoueÄÖÜÉ”

I can’t find however find a bug in the bug tracking system.  
Doesn’t this qualify as a bug?

Cheers, Stefan

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 1:34am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/2 "2008-07-10T01:34:25Z")

</div>

Hi,

In message “Re: String#upcase/downcase with UTF-8 strings in Ruby 1.9”  
on Thu, 10 Jul 2008 07:09:29 +0900, “Stefan S.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|in Ruby 1.9 I get the following behaviour:  
|  
|\>\> “aoueäöüé”.upcase  
|=\> “AOUEäöüé”  
|\>\> “AOUEÄÖÜÉ”.downcase  
|=\> “aoueÄÖÜÉ”  
|  
|I can’t find however find a bug in the bug tracking system.  
|Doesn’t this qualify as a bug?

The document for String#upcase says:

call-seq:  
str.upcase =\> new\_str

Returns a copy of _str_ with all lowercase letters replaced with  
their  
uppercase counterparts. The operation is locale insensitive—only  
characters `a'' to `z’’ are affected.  
Note: case replacement is effective only in ASCII region.

```
 "hEllO".upcase #=> "HELLO"

```

See “Note:”. Tim B. have persuaded me to do so, since case  
conversion outside of ASCII region is highly dependent on country,  
language, culture and script.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 3:22am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/3 "2008-07-10T03:22:03Z")

</div>

> The document for String#upcase says:

Yes, sorry, I should have read the documentation

> See “Note:”. Tim B. have persuaded me to do so, since case  
> conversion outside of ASCII region is highly dependent on country,  
> language, culture and script.

So basically the Python guys are going down a wrong route ?

# -_- coding: utf-8 -_-

import string  
print string.upper(u"aoueäöüé")  
print string.lower(u"AOUEÄÖÜÉ")

works as expected.

Cheers, Stefan

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 3:30am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/4 "2008-07-10T03:30:14Z")

</div>

On Jul 9, 2008, at 8:17 PM, Stefan S. wrote:

> # -_- coding: utf-8 -_-
> 
> import string  
> print string.upper(u"aoueäöüé")  
> print string.lower(u"AOUEÄÖÜÉ")
> 
> works as expected.
> 
> Cheers, Stefan

No.  
They’re going down a different route.  
Seriously, the language handling is something that could easily be  
handled by extensions. It does not need to be a core part of the  
language.  
Even operating systems handle these things with proprietary and very  
sophisticated techniques based on the language in question.  
In most cases, what you are expecting to be the correct upper case  
characters may be ‘correct’ but it will ultimately depend on the  
language and the context.

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 2:24am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/5 "2008-07-10T02:24:11Z")

</div>

On Jul 9, 2008, at 6:25 PM, Yukihiro M. wrote:

> |=\> “aoueÄÖÜÉ”  
> with their  
> matz.

This leaves the perfect opening for people to contribute locale or  
language specific extensions to String.  
It would make a great gem with a plug-in architecture.  
Just add options for the language you want to use.  
In any case it can get very tricky to do character conversions with  
different languages.

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 10, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/6 "2008-07-10T17:43:52Z")

</div>

> > 
> 
> No.  
> They’re going down a different route.  
> Seriously, the language handling is something that could easily be  
> handled by extensions. It does not need to be a core part of the  
> language.

Is Nikolai W.'s Ruby Character Encodings Library [1] currently the  
best way to go?

Stefan

[1] [http://bitwi.se/software/ruby/character-encodings/](http://bitwi.se/software/ruby/character-encodings/)

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 11, 2008, 7:34am UTC](https://www.ruby-forum.com/t/string-upcase-downcase-with-utf-8-strings-in-ruby-1-9/142639/7 "2008-07-11T07:34:51Z")

</div>

> Seriously, the language handling is something that could easily be  
> handled by extensions. It does not need to be a core part of the  
> language.

Are there any working extensions for Ruby 1.9 that offer Unicode support  
for String#downcase/upcase and/or Array#sort?

Stefan
