I
Iñaki Baz Castillo
Hi, I've added a method "multi_capitalize" to String class. This
method is done in C and basically modifies the string:
"record-roUTE".multi_capitalize =3D> "Record-Route"
The problem is that after the method execution, the new String has
ASCII-8BIT encoding, while the original string had UTF-8 (using Ruby
1.9.1).
---------------------------------------------------------------------------=
-----
irb> hname =3D "record-rouTE-=E2=82=AC"
"record-rouTE-=E2=82=AC"
irb> hname.encoding
#<Encoding:UTF-8>
irb> hname2 =3D hname.multi_capitalize
"Record-Route-\xE2\x82\xAC" <------- !!!
irb> hname2.encoding
#<Encoding:ASCII-8BIT> <------- !!!
irb> hname2.force_encoding("utf-8")
"Record-Route-=E2=82=AC"
irb> hname2.encoding
#<Encoding:UTF-8>
---------------------------------------------------------------------------=
-----
What should I add to my C method to mantain the UTF-8 codification
after the changes in the string?
Could I invoke the C "force_encoding()" function from the C code
before returning the modified string? How to invoke it?
Thanks a lot.
--=20
I=C3=B1aki Baz Castillo
<[email protected]>
method is done in C and basically modifies the string:
"record-roUTE".multi_capitalize =3D> "Record-Route"
The problem is that after the method execution, the new String has
ASCII-8BIT encoding, while the original string had UTF-8 (using Ruby
1.9.1).
---------------------------------------------------------------------------=
-----
irb> hname =3D "record-rouTE-=E2=82=AC"
"record-rouTE-=E2=82=AC"
irb> hname.encoding
#<Encoding:UTF-8>
irb> hname2 =3D hname.multi_capitalize
"Record-Route-\xE2\x82\xAC" <------- !!!
irb> hname2.encoding
#<Encoding:ASCII-8BIT> <------- !!!
irb> hname2.force_encoding("utf-8")
"Record-Route-=E2=82=AC"
irb> hname2.encoding
#<Encoding:UTF-8>
---------------------------------------------------------------------------=
-----
What should I add to my C method to mantain the UTF-8 codification
after the changes in the string?
Could I invoke the C "force_encoding()" function from the C code
before returning the modified string? How to invoke it?
Thanks a lot.
--=20
I=C3=B1aki Baz Castillo
<[email protected]>