[MacRuby-devel] converting UTF-8 to MacRoman still output UTF-8
Yvon Thoraval
yvon.thoraval at gmail.com
Wed Apr 21 06:14:29 PDT 2010
I've found a workover :
def to_macroman(str)
data = CFStringCreateExternalRepresentation(nil, str,
KCFStringEncodingMacRoman, 0)
if data.nil?
raise "can't retrieve data from `#{str}'"
end
dest = "".force_encoding("MacRoman")
#
# force dest to be of "MacRoman"
#
dest += CFStringCreateFromExternalRepresentation(nil, data,
KCFStringEncodingMacRoman)
#____^_______ new
#
if dest.nil?
raise "can't convert data from `#{str}'"
end
CFRelease(data)
#CFRelease(dest)
#
# commented otherwise i get a malloc error
# may be it's ruby here making GC ?
#
dest.mutableCopy
return dest
end
giving the right output :
une phrase accentuée, ça vous va ?
str.size = 34, str.encoding = UTF-8
macroman.size = 36, macroman.encoding = macRoman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100421/aa6463dd/attachment.html>
More information about the MacRuby-devel
mailing list