Prev: ruby
Next: Finding dynamic Div tag using its innertext
From: =?ISO-8859-1?Q?Une_B=E9vue?= on 22 Apr 2010 05:17 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 ! -- � Si l'on sait exactement ce qu'on va faire, � quoi bon le faire ? � (Pablo Picasso)
|
Pages: 1 Prev: ruby Next: Finding dynamic Div tag using its innertext |