• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Semi-OT: WebCore > decodeData:, no longer working?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Semi-OT: WebCore > decodeData:, no longer working?


  • Subject: Semi-OT: WebCore > decodeData:, no longer working?
  • From: j o a r <email@hidden>
  • Date: Fri, 14 Jan 2005 10:14:00 +0100

Hello list!

I seem to remember that I could use WebCore to decode HTML data and have it return a NSString. I would like to use WebCore as it's good at detecting the proper encoding for HTML data. Anyway, I can't get it to work. I guess that:

1) I'm not supposed to use the "decodeData:"; method like that
2) It's broken

Does anyone have any comments or suggestions?

======================================================
#import <Foundation/Foundation.h>
#import <WebCore/WebCoreEncodings.h>

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSData *htmlData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://www.apple.com/index.html";]];

NSLog(@"htmlData: %d", [htmlData length]);


NSString *HTMLString = [WebCoreEncodings decodeData: htmlData];

// Yes, grabbing a range without checking the length of the receiver
// could crash - this is just sample code...
NSLog(@"WebCore htmlString: %d (snippet: \"%@\")", [HTMLString length], ((HTMLString != nil) ? [HTMLString substringWithRange: NSMakeRange(0, 6)] : @""));

// OK, so NSISOLatin1StringEncoding might not be absolutely correct, but
// that's the whole point of why I try to use the method from WebCore...
HTMLString = [[[NSString alloc] initWithData: htmlData encoding: NSISOLatin1StringEncoding] autorelease];

NSLog(@"NSString htmlString: %d (snippet: \"%@\")", [HTMLString length], ((HTMLString != nil) ? [HTMLString substringWithRange: NSMakeRange(0, 6)] : @""));

[pool release];

return 0;
}
======================================================


j o a r

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Know about Mutability
  • Next by Date: Re: Zip-files
  • Previous by thread: Keychain wierdness
  • Next by thread: Fastest way to build an attributed string
  • Index(es):
    • Date
    • Thread