On 31 Jul 2014, at 5:05 am, Gil Dawson <email@hidden> wrote:
Where is TextWrangler getting this information?
On Aug 1, 2014, at 5:00 AM, Shane Stanley wrote: From an extended attribute saved with the file, under the name com.apple.TextEncoding.
So, when I used TextEdit to create those three ".txt" files, each with a different encoding in the "Save As..." dialog...
One to UTF-8 One to Western (MacOS Roman) One to Western (Windows Latin 1)
...the three files were not "plain text" files, but each must have had had an extended attribute saved with it (somewhere).
I was wondering is there any way to pick up this extended attribute from within ASObj-C. Then I looked through the NSString class methods and I found: stringWithContentsOfFile:usedEncoding:error:Returns a string created by reading data from the file at a given path and returns by reference the encoding used to interpret the file. + (id)stringWithContentsOfFile:(NSString *) path usedEncoding:(NSStringEncoding *) enc error:( NSError **) errorParameters- path
A path to a file. - enc
Upon return, if the file is read successfully, contains the encoding used to interpret the file atpath. - error
If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL .
And then... The following constants are provided by NSString as possible string encodings.
Perfect!
Thanks for the suggestion, Shane!
--Gil |