Changeset 957

Show
Ignore:
Timestamp:
11/13/2009 09:33:26 AM (2 years ago)
Author:
gbooker
Message:

Work around sloppiness on the part of TVRage's webmasters who cannot understand what character encodings mean.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/Extension/NSXMLDocument-Extensions.m

    r955 r957  
    3737        NSStringEncoding responseEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[response textEncodingName])); 
    3838        NSString *documentString = [[NSString alloc] initWithData:documentData encoding:responseEncoding]; 
     39        if(documentString == nil) 
     40        { 
     41                //Most likely this is UTF-8 and some moron doesn't understand that the meta tags need to follow the same encoding. 
     42                NSMutableData *mutData = [documentData mutableCopy]; 
     43                int length = [mutData length]; 
     44                const char *bytes = [mutData bytes]; 
     45                const char *location; 
     46                while((location = strnstr(bytes, "<meta", length)) != NULL) 
     47                { 
     48                        int offset = location - bytes; 
     49                        const char *end = strnstr(location, ">", length-offset); 
     50                        if(end != NULL) 
     51                        { 
     52                                int replaceLength = end-location+2; 
     53                                [mutData replaceBytesInRange:NSMakeRange(offset, replaceLength) withBytes:"" length:0]; 
     54                                bytes = [mutData bytes]; 
     55                                length = [mutData length]; 
     56                        } 
     57                        else 
     58                                break; 
     59                } 
     60                documentString = [[NSString alloc] initWithData:mutData encoding:responseEncoding]; 
     61                [mutData release]; 
     62        } 
    3963         
    4064        NSXMLDocument *ret = [[[NSXMLDocument alloc] initWithXMLString:documentString options:NSXMLDocumentTidyHTML error:error] autorelease];