• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to detect string encoding before reading a file in NSString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to detect string encoding before reading a file in NSString?


  • Subject: Re: How to detect string encoding before reading a file in NSString?
  • From: Nick Zitzmann <email@hidden>
  • Date: Tue, 26 Apr 2011 12:53:06 -0600

On Apr 26, 2011, at 12:49 PM, Laurent Daudelin wrote:

>> TextEdit's encoding guesser just uses the built-in NSAttributedString method -initWithURL:options:documentAttributes:error:, which will guess the file's encoding when opening it. But it has been mentioned that heuristics are not infallible, and this method's heuristics are no exception. It does a good job overall, but I've found that it usually misinterprets UTF-8 format text.
>
> Yes, I know that all the guess jobs can fail. I was starting to be excited when started reading your reply but if it usually misinterprets UTF-8, that's a pretty significant problem...

That was a long time ago, so it may have been fixed. But if it's still happening, then one workaround would be to try and open the file as UTF-8 first, and if that fails, then fall back on the above method. The UTF-8 parser often returns nil on text that is not in UTF-8 format IIRC.

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to detect string encoding before reading a file in NSString?
      • From: John Pannell <email@hidden>
References: 
 >How to detect string encoding before reading a file in NSString? (From: Laurent Daudelin <email@hidden>)
 >Re: How to detect string encoding before reading a file in NSString? (From: Nick Zitzmann <email@hidden>)
 >Re: How to detect string encoding before reading a file in NSString? (From: Laurent Daudelin <email@hidden>)

  • Prev by Date: Re: How to detect string encoding before reading a file in NSString?
  • Next by Date: Re: How to detect string encoding before reading a file in NSString?
  • Previous by thread: Re: How to detect string encoding before reading a file in NSString?
  • Next by thread: Re: How to detect string encoding before reading a file in NSString?
  • Index(es):
    • Date
    • Thread