Re: Determine encoding of file
Re: Determine encoding of file
- Subject: Re: Determine encoding of file
- From: Kyle Sluder <email@hidden>
- Date: Fri, 30 Jul 2010 15:26:01 -0700
On Fri, Jul 30, 2010 at 3:09 PM, Dave DeLong <email@hidden> wrote:
> Hi everyone,
>
> I have a seemingly simple question, but I haven't been able to figure it out.
>
> Given a file, how can I determine the NSStringEncoding of the file, without reading the entire file into memory? (If the file isn't a text file, then defaulting to NSUTF8StringEncoding is just fine, since my code will only work properly if I'm working with text files anyway)
There's no standard heuristic for doing this. Windows has one built in
called MLang that IE uses, but I don't think the heuristic itself is
published. Encoding detection also happens to be the source of many
humorous "bugs" in Notepad:
http://blogs.msdn.com/b/michkap/archive/2006/06/14/631016.aspx
> I've found this: http://www.macosxguru.net/article.php?story=20030808081801868 but it seems ridiculously complex...
That is pretty poorly engineered code: an explosion of classes for no
good reason. If I were to write an encoding detector, it would
probably be a much simpler big if block.
--Kyle Sluder
_______________________________________________
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