#import <Foundation/Foundation.h>

int main(int argc, const char *argv[])
{
  CREATE_AUTORELEASE_POOL(arp);

  NSString *url = @"http://p.o.roussel@free.fr:password@127.0.0.1/dav.php/calendars/p.o.roussel@free.fr/default/";
  NSString *escapedUrl = @"http://p.o.roussel%40free.fr:password@127.0.0.1/dav.php/calendars/p.o.roussel@free.fr/default/";
  NSString *user = @"p.o.roussel@free.fr";
  NSString *escapedUser = [user stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAllowedCharacterSet]];
  NSLog(@"escaped user : %@", escapedUser);
  // => OK : p.o.roussel%40free.fr

  NSURL *fromString = [NSURL URLWithString:url];
  NSLog(@"fromString : %@", [fromString absoluteString]);
  // => OK : nil


  NSURL *fromEscapedString = [NSURL URLWithString:escapedUrl];
  NSLog(@"fromEscapedString : %@", [fromEscapedString absoluteString]);
  // => OK : http://p.o.roussel%40free.fr:password@127.0.0.1/dav.php/calendars/p.o.roussel@free.fr/default/


  NSURL *fromParts = [[NSURL alloc] initWithScheme:@"http"
					      user:user
					  password:@"password"
					      host:@"127.0.0.1"
					      port:[NSNumber numberWithInt:80]
					  fullPath:@"dav.php/calendars/p.o.roussel@free.fr/default/"
				   parameterString:nil
					     query:nil
					  fragment:nil];
  NSLog(@"fromParts %@", [fromParts absoluteString]);
  // => nil, could auto escape user ?

  NSURL *fromEscapedParts = [[NSURL alloc] initWithScheme:@"http"
						     user:escapedUser
						 password:@"password"
						     host:@"127.0.0.1"
						     port:nil
						 fullPath:@"dav.php/calendars/p.o.roussel@free.fr/default/"
					  parameterString:nil
						    query:nil
						 fragment:nil];
  NSLog(@"fromEscapedParts %@", [fromEscapedParts absoluteString]);
  // => KO : http://p.o.roussel%2540free.fr:password@127.0.0.1/dav.php/calendars/p.o.roussel@free.fr/default/


  RELEASE(arp);
  return 0;
}
