Hi Dave-

I have some code I've been using for a few years for this purpose... when I 
consulted Google on the source of the TECSniffer class that I have, the search 
was not revealing.  So... I've posted the class files here:

http://www.positivespinmedia.com/dev/TEC.zip

I believe it is using some carbon-y Text Encoding Converter goodness, but could 
not say for sure.  The code is called like so in my app:

TECSniffer *sniffer = [[TECSniffer alloc] initWithWebTextEncodings];
        NSArray *results = [sniffer sniff:_htmldata];
        while(!htmlString && i < [results count]){
            htmlString = [[NSString alloc] initWithData:_htmldata 
encoding:[[results objectAtIndex:i] unsignedIntValue]];
        }

I didn't write the original code, and couldn't track down the origination of 
it.  Perhaps it will help!

John

On Jul 30, 2010, at 4:09 PM, Dave DeLong wrote:
> 
> 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)
> 
> I've found this: 
> http://www.macosxguru.net/article.php?story=20030808081801868 but it seems 
> ridiculously complex...
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to