Committed by
Ben Copsey
Provide encoding to htmlReadFile() and htmlReadMemory()
Showing
1 changed file
with
53 additions
and
2 deletions
| @@ -145,6 +145,57 @@ static NSMutableArray *requestsUsingXMLParser = nil; | @@ -145,6 +145,57 @@ static NSMutableArray *requestsUsingXMLParser = nil; | ||
| 145 | [[self externalResourceQueue] go]; | 145 | [[self externalResourceQueue] go]; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | +- (const char *)encodingName | ||
| 149 | +{ | ||
| 150 | + xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE; | ||
| 151 | + switch ([self responseEncoding]) | ||
| 152 | + { | ||
| 153 | + case NSASCIIStringEncoding: | ||
| 154 | + encoding = XML_CHAR_ENCODING_ASCII; | ||
| 155 | + break; | ||
| 156 | + case NSJapaneseEUCStringEncoding: | ||
| 157 | + encoding = XML_CHAR_ENCODING_EUC_JP; | ||
| 158 | + break; | ||
| 159 | + case NSUTF8StringEncoding: | ||
| 160 | + encoding = XML_CHAR_ENCODING_UTF8; | ||
| 161 | + break; | ||
| 162 | + case NSISOLatin1StringEncoding: | ||
| 163 | + encoding = XML_CHAR_ENCODING_8859_1; | ||
| 164 | + break; | ||
| 165 | + case NSShiftJISStringEncoding: | ||
| 166 | + encoding = XML_CHAR_ENCODING_SHIFT_JIS; | ||
| 167 | + break; | ||
| 168 | + case NSISOLatin2StringEncoding: | ||
| 169 | + encoding = XML_CHAR_ENCODING_8859_2; | ||
| 170 | + break; | ||
| 171 | + case NSISO2022JPStringEncoding: | ||
| 172 | + encoding = XML_CHAR_ENCODING_2022_JP; | ||
| 173 | + break; | ||
| 174 | + case NSUTF16BigEndianStringEncoding: | ||
| 175 | + encoding = XML_CHAR_ENCODING_UTF16BE; | ||
| 176 | + break; | ||
| 177 | + case NSUTF16LittleEndianStringEncoding: | ||
| 178 | + encoding = XML_CHAR_ENCODING_UTF16LE; | ||
| 179 | + break; | ||
| 180 | + case NSUTF32BigEndianStringEncoding: | ||
| 181 | + encoding = XML_CHAR_ENCODING_UCS4BE; | ||
| 182 | + break; | ||
| 183 | + case NSUTF32LittleEndianStringEncoding: | ||
| 184 | + encoding = XML_CHAR_ENCODING_UCS4LE; | ||
| 185 | + break; | ||
| 186 | + case NSNEXTSTEPStringEncoding: | ||
| 187 | + case NSSymbolStringEncoding: | ||
| 188 | + case NSNonLossyASCIIStringEncoding: | ||
| 189 | + case NSUnicodeStringEncoding: | ||
| 190 | + case NSMacOSRomanStringEncoding: | ||
| 191 | + case NSUTF32StringEncoding: | ||
| 192 | + default: | ||
| 193 | + encoding = XML_CHAR_ENCODING_ERROR; | ||
| 194 | + break; | ||
| 195 | + } | ||
| 196 | + return xmlGetCharEncodingName(encoding); | ||
| 197 | +} | ||
| 198 | + | ||
| 148 | - (void)parseAsHTML | 199 | - (void)parseAsHTML |
| 149 | { | 200 | { |
| 150 | webContentType = ASIHTMLWebContentType; | 201 | webContentType = ASIHTMLWebContentType; |
| @@ -160,10 +211,10 @@ static NSMutableArray *requestsUsingXMLParser = nil; | @@ -160,10 +211,10 @@ static NSMutableArray *requestsUsingXMLParser = nil; | ||
| 160 | 211 | ||
| 161 | /* Load XML document */ | 212 | /* Load XML document */ |
| 162 | if ([self downloadDestinationPath]) { | 213 | if ([self downloadDestinationPath]) { |
| 163 | - doc = htmlReadFile([[self downloadDestinationPath] cStringUsingEncoding:NSUTF8StringEncoding], NULL, HTML_PARSE_NONET | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR); | 214 | + doc = htmlReadFile([[self downloadDestinationPath] cStringUsingEncoding:NSUTF8StringEncoding], [self encodingName], HTML_PARSE_NONET | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR); |
| 164 | } else { | 215 | } else { |
| 165 | NSData *data = [self responseData]; | 216 | NSData *data = [self responseData]; |
| 166 | - doc = htmlReadMemory([data bytes], (int)[data length], "", NULL, HTML_PARSE_NONET | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR); | 217 | + doc = htmlReadMemory([data bytes], (int)[data length], "", [self encodingName], HTML_PARSE_NONET | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR); |
| 167 | } | 218 | } |
| 168 | if (doc == NULL) { | 219 | if (doc == NULL) { |
| 169 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:101 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Error: unable to parse reponse XML",NSLocalizedDescriptionKey,nil]]]; | 220 | [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:101 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Error: unable to parse reponse XML",NSLocalizedDescriptionKey,nil]]]; |
-
Please register or login to post a comment