Created
September 23, 2011 05:07
-
-
Save davedelong/1236778 to your computer and use it in GitHub Desktop.
Snippet to discover the BOM of a text encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSData *bom = nil; | |
NSStringEncoding encoding = ...; | |
NSData *a = [@"a" dataUsingEncoding:encoding]; | |
NSData *aa = [@"aa" dataUsingEncoding:encoding]; | |
if ([a length] * 2 != [aa length]) { | |
NSUInteger characterLength = [aa length] - [a length]; | |
bom = [a subdataWithRange:NSMakeRange(0, [a length]-characterLength)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment