@@ -23,21 +23,29 @@ + (BOOL)decodeTextData:(NSData*)fileDataIn
23
23
}
24
24
25
25
// Discover and set line endings type (dos, old Mac or unix)
26
- NSString * newLinesFound = nil ;
26
+ NSString * newLinesFound = nil ;
27
27
if (!error) {
28
+ NSInteger nLocation = stringASCII ? [stringASCII rangeOfString: @" \n " ].location : 0 ;
28
29
NSInteger rLocation = stringASCII ? [stringASCII rangeOfString: @" \r " ].location : 0 ;
29
- NSInteger nLocation = stringASCII ? [stringASCII rangeOfString: @" \n " ].location : 0 ;
30
-
30
+
31
31
// Set to whichever occurs first in the file: \r\n, \r or \n
32
- if (nLocation == rLocation + 1 ) {
33
- newLinesFound = @" \r\n " ;
34
- }
35
- else if (rLocation < nLocation) {
36
- newLinesFound = @" \r " ;
37
- }
38
- else {
39
- newLinesFound = @" \n " ;
40
- }
32
+ if (nLocation != NSNotFound ) {
33
+ if (rLocation != NSNotFound ) {
34
+ if (nLocation == rLocation + 1 ) {
35
+ newLinesFound = @" \r\n " ;
36
+ } else if (nLocation < rLocation) {
37
+ newLinesFound = @" \n " ;
38
+ } else {
39
+ newLinesFound = @" \r " ;
40
+ }
41
+ } else {
42
+ newLinesFound = @" \n " ;
43
+ }
44
+ } else if (rLocation != NSNotFound ) {
45
+ newLinesFound = @" \r " ;
46
+ } else {
47
+ newLinesFound = @" \n " ;
48
+ }
41
49
}
42
50
43
51
NSString *utfdash8Key = @" content=\" text/html; charset=utf-8" ;
0 commit comments