ObjFW  Check-in [12a4d43f67]

Overview
Comment:OFURL: Add +[URL].

This also makes -[description] more robust, as with this change, it is
now possible that required parts of the URL are nil.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 12a4d43f67511c0dbe36c36093c1356d2396ec82bb3d73ff430e32162ea60b4f
User & Date: js on 2012-12-11 12:12:33
Original User & Date: js on 2012-12-11 12:12:34
Other Links: manifest | tags
Context
2012-12-11
12:12
Add OFHTTPServer. check-in: 190b9d3a5c user: js tags: trunk
12:12
OFURL: Add +[URL]. check-in: 12a4d43f67 user: js tags: trunk
12:12
OFTCPSocket: Fix a bug in -[accept]. check-in: baa6951ec0 user: js tags: trunk
Changes

Modified src/OFURL.h from [7d9024f690] to [0221f4c097].

43
44
45
46
47
48
49








50
51
52
53
54
55
56
@property (copy) OFString *password;
@property (copy) OFString *path;
@property (copy) OFString *parameters;
@property (copy) OFString *query;
@property (copy) OFString *fragment;
#endif









/*!
 * Creates a new URL with the specified string.
 *
 * @param string A string describing a URL
 * @return A new, autoreleased OFURL
 */
+ (instancetype)URLWithString: (OFString*)string;







>
>
>
>
>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@property (copy) OFString *password;
@property (copy) OFString *path;
@property (copy) OFString *parameters;
@property (copy) OFString *query;
@property (copy) OFString *fragment;
#endif

/*!
 * Creates a new URL.
 *
 * @param string A string describing a URL
 * @return A new, autoreleased OFURL
 */
+ (instancetype)URL;

/*!
 * Creates a new URL with the specified string.
 *
 * @param string A string describing a URL
 * @return A new, autoreleased OFURL
 */
+ (instancetype)URLWithString: (OFString*)string;

Modified src/OFURL.m from [7c53691cc2] to [3b200a0eea].

74
75
76
77
78
79
80





81
82
83
84
85
86
87

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

@implementation OFURL





+ (instancetype)URLWithString: (OFString*)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

+ (instancetype)URLWithString: (OFString*)string
		relativeToURL: (OFURL*)URL







>
>
>
>
>







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

@implementation OFURL
+ (instancetype)URL
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)URLWithString: (OFString*)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

+ (instancetype)URLWithString: (OFString*)string
		relativeToURL: (OFURL*)URL
509
510
511
512
513
514
515

516

517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
- (OFString*)string
{
	OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://",
								  scheme];
	BOOL needPort = YES;

	if ([scheme isEqual: @"file"]) {

		[ret appendString: path];

		return ret;
	}

	if (user != nil && password != nil)
		[ret appendFormat: @"%@:%@@", user, password];
	else if (user != nil)
		[ret appendFormat: @"%@@", user];


	[ret appendString: host];

	if (([scheme isEqual: @"http"] && port == 80) ||
	    ([scheme isEqual: @"https"] && port == 443))
		needPort = NO;

	if (needPort)
		[ret appendFormat: @":%d", port];


	[ret appendString: path];

	if (parameters != nil)
		[ret appendFormat: @";%@", parameters];

	if (query != nil)
		[ret appendFormat: @"?%@", query];








>
|
>








>
|








>
|







514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
- (OFString*)string
{
	OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://",
								  scheme];
	BOOL needPort = YES;

	if ([scheme isEqual: @"file"]) {
		if (path != nil)
			[ret appendString: path];

		return ret;
	}

	if (user != nil && password != nil)
		[ret appendFormat: @"%@:%@@", user, password];
	else if (user != nil)
		[ret appendFormat: @"%@@", user];

	if (host != nil)
		[ret appendString: host];

	if (([scheme isEqual: @"http"] && port == 80) ||
	    ([scheme isEqual: @"https"] && port == 443))
		needPort = NO;

	if (needPort)
		[ret appendFormat: @":%d", port];

	if (path != nil)
		[ret appendString: path];

	if (parameters != nil)
		[ret appendFormat: @";%@", parameters];

	if (query != nil)
		[ret appendFormat: @"?%@", query];