Laurent Daudelin wrote:

I've found different ways to do that (some pure Cocoa, some using Carbon) but I was wondering about the wisdom of this list as to what is the best way to detect the encoding of a file before passing it to NSString initWithContentsOfFile:encoding:error:?


You might not have to guess at all, if the file has an xattr of "com.apple.TextEncoding" attached to it. I don't know if any of the NSString encoding-guessing methods use this xattr or not. It's easy to test, though: TextEdit.app writes the xattr when you Save As and choose an encoding.

The contents of the xattr is a text-encoding name (such as "utf-8"), then a semicolon, then a longish decimal number.

You can see a file's xattrs with the xattr command in Terminal. Type 'xattr -h' for a summary of options and args. The xattr API works great in C (BSD functions, exist since OS 10.4 Tiger).

Google search terms:
xattr site:developer.apple.com

  -- GG

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to