Re: Determine encoding of file

2010-07-31 Thread Dave DeLong
Thanks to everyone who responded with ideas on this. John's suggestion of the TEC* functions was promising, but I ended up not using them when I discovered that they're not available on the iPhone. Ditto for Martin's suggestion of using getxattr. I eventually ended up using Rainer's method (wh

Re: Determine encoding of file

2010-07-30 Thread Michael Ash
On Fri, Jul 30, 2010 at 6:24 PM, Nick Zitzmann wrote: > > On Jul 30, 2010, at 4:09 PM, Dave DeLong 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 >> read

Re: Determine encoding of file

2010-07-30 Thread Rainer Brockerhoff
At 16:06 -0700 30/07/10, cocoa-dev-requ...@lists.apple.com wrote: >From: Dave DeLong >Date: Fri, 30 Jul 2010 16:09:22 -0600 >Message-ID: >... >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

Re: Determine encoding of file

2010-07-30 Thread Michael Watson
And, of course, as Nick Z and that session point out, you may need to allow the user to choose the encoding somehow in your application, given you can't be 100% accurate when the encoding is unknown. -- michael On 30 Jul, 2010, at 17:35, Michael Watson wrote: > There's a good session from WWD

Re: Determine encoding of file

2010-07-30 Thread Michael Watson
There's a good session from WWDC 2009, 112 - Text Processing in Cocoa, that has a segment about guessing encodings without having to read the entire file (in most cases). It's worth watching, even if it doesn't solve your problem directly. -- michael On 30 Jul, 2010, at 15:09, Dave DeLong wro

Re: Determine encoding of file

2010-07-30 Thread Martin Wierschin
Given a file, how can I determine the NSStringEncoding of the file, without reading the entire file into memory? Some files may have a text encoding attribute set, which you can read using getxattr and "com.apple.textEncoding". Probably you won't have the luxury of just using that API, but

Re: Determine encoding of file

2010-07-30 Thread John Pannell
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 som

Re: Determine encoding of file

2010-07-30 Thread Kyle Sluder
On Fri, Jul 30, 2010 at 3:09 PM, Dave DeLong 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 fi

Re: Determine encoding of file

2010-07-30 Thread Nick Zitzmann
On Jul 30, 2010, at 4:09 PM, Dave DeLong 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 fil

Determine encoding of file

2010-07-30 Thread Dave DeLong
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, sinc