UTF-8 to MacRoman conversion

I need to convert a String from UTF-8 to MacRoman, MacRuby makes use of
a “special” iconv.rb.

When doing a Mac Roman to UTF-8 converions no prob however when doing
reversal from UTF-8 to MacRoman the String is still in UTF-8.

Here is my code :
puts “UTF-8 back to MacRoman :”
mcr = Iconv.iconv(‘macintosh’, ‘utf-8’,
str_utf8).split(/#{LF}/).join(CR)
puts “#{mcr.size} chars, #{mcr.encoding}”

giving :

=> 34 chars, UTF-8

the icon.rb file (from MacRuby) being :

def iconv(str, start=0, length=-1)
# Not sure if it’s the right thing to do…
data = CFStringCreateExternalRepresentation(nil, str, @to_enc, 0)
if data.nil?
raise “can’t retrieve data from #{str}'" end dest = CFStringCreateFromExternalRepresentation(nil, data, @to_enc) if dest.nil? raise "can't convert data from#{str}’”
end
CFRelease(data)
CFRelease(dest)
dest.mutableCopy
end

which seems to work from “some encoding” to UTF-8 but not the reverse…

I’d like to help the designer but i’m lost in Apple’s documentation
about CFStringxyz !

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs