Permalink
Browse files

Added support for recognizing ISO 2022-KR encoding

  • Loading branch information...
1 parent d46f499 commit 12f1510d6577e9c4d9c98fc919ddb62fd253c3a7 @davedelong committed Dec 23, 2012
Showing with 11 additions and 8 deletions.
  1. +3 −0 CHCSVParser/CHCSVParser.m
  2. +8 −8 README.markdown
@@ -155,6 +155,9 @@ - (void)_sniffEncoding {
} else if (bufferLength > 3 && bytes[0] == 0xFF && bytes[1] == 0xFE && bytes[2] == 0x00 && bytes[3] == 0x00) {
encoding = NSUTF32LittleEndianStringEncoding;
bomLength = 4;
+ } else if (bufferLength > 3 && bytes[0] == 0x1B && bytes[1] == 0x24 && bytes[2] == 0x29 && bytes[3] == 0x43) {
+ encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISO_2022_KR);
+ bomLength = 4;
} else if (bufferLength > 1 && bytes[0] == 0xFE && bytes[1] == 0xFF) {
encoding = NSUTF16BigEndianStringEncoding;
bomLength = 2;
View
@@ -54,13 +54,13 @@ There are a couple of category methods on `NSArray` and `NSString` to simplify t
##Data Encoding
`CHCSVParser` relies on knowing the encoding of the CSV file. It should work with pretty much any kind of file encoding, if you can provide what that encoding is. If you do not know the encoding of the file, then `CHCSVParser` can make a naïve guess. `CHCSVParser` will try to guess the encoding of the file from among these options:
- - `NSMacOSRomanStringEncoding` (the default/fallback encoding)
- - `NSUTF8StringEncoding`
- - `NSUTF16BigEndianStringEncoding`
- - `NSUTF16LittleEndianStringEncoding`
- - `NSUTF32BigEndianStringEncoding`
- - `NSUTF32LittleEndianStringEncoding`
-
+ - MacOS Roman (`NSMacOSRomanStringEncoding`; the default/fallback encoding)
+ - UTF-8 (`NSUTF8StringEncoding`)
+ - UTF-16BE (`NSUTF16BigEndianStringEncoding`)
+ - UTF-16LE (`NSUTF16LittleEndianStringEncoding`)
+ - UTF-32BE (`NSUTF32BigEndianStringEncoding`)
+ - UTF-32LE (`NSUTF32LittleEndianStringEncoding`)
+ - ISO 2022-KR (`kCFStringEncodingISO_2022_KR`)
##Performance
`CHCSVParser` is conscious of low-memory environments, such as the iPhone or iPad. It can safely parse very large CSV files, because it only loads portions of the file into memory at a single time.
@@ -72,7 +72,7 @@ There are a couple of category methods on `NSArray` and `NSString` to simplify t
`CHCSVParser` uses code to discover file encoding that was provided by [Rainer Brockerhoff][2].
[1]: http://davedelong.com
- [2]: http://brockerhoff.net/
+ [2]: http://brockerhoff.net
##License

0 comments on commit 12f1510

Please sign in to comment.