rubymotion-community / sugarcube

Some sugar for your cocoa. RubyMotion helpers.
Other
422 stars 66 forks source link

attributed_html not converting french characters to proper format #214

Closed naiyyar closed 7 years ago

naiyyar commented 7 years ago

Hi,

This my json string "

Développer nouveau site

".

desc =   "<p>Développer nouveau site</p>"
desc.attributed_html.to_s

OUTPUT IS: "Développer nouveau site\n"

How can i get the output string in readable format?

colinta commented 7 years ago

You might want to pull the code out of the attributed_html method and play with the encoding and options to see if you can fix it. Unfortunately I can't compile sugarcube at the moment, so I can't reproduce this.

naiyyar commented 7 years ago

I just want the same output when using attributed_html on it as it is in json. I don't know why attributed_html is not encoding french characters properly as you can see above code block before applying attibuted_html string is Développer and after Développer.

naiyyar commented 7 years ago

Thanks @colinta Solved by using below code

class NSString

  def attributed_html
     options = { NSDocumentTypeDocumentAttribute => NSHTMLTextDocumentType, 
      NSCharacterEncodingDocumentAttribute => NSUTF8StringEncoding }
    #options = { NSDocumentTypeDocumentAttribute => NSHTMLTextDocumentType}
    NSAttributedString.alloc.initWithData(self.dataUsingEncoding(NSUTF8StringEncoding), options:options, documentAttributes:nil, error:nil)
  end

end
colinta commented 7 years ago

Awesome! Please consider creating a pull request and adding this fix to sugarcube! 😃

colinta commented 7 years ago

I'm disappointed that you found the fix but then didn't open a pull request. That's how we make software better! I'll include this in a patch release version.