ObjFW  Check-in [03e111614e]

Overview
Comment:OFURL: Add -[URLEncoded*] for encoded components
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 03e111614e7c6c250737e13ad79256c22a7f6eae223e05c42196f941e0c74971
User & Date: js on 2017-10-31 22:06:31
Other Links: manifest | tags
Context
2017-10-31
22:18
OFHTTPClient: Adjust to OFURL change check-in: 35b398fae4 user: js tags: trunk
22:06
OFURL: Add -[URLEncoded*] for encoded components check-in: 03e111614e user: js tags: trunk
21:55
OFString+URLEncoding: Change default allowed chars check-in: 4db6713bda user: js tags: trunk
Changes

Modified src/OFURL.h from [a6d37c0b2c] to [2730012cb2].

37
38
39
40
41
42
43






44
45
46
47
48






49
50
51
52
53
54
55
56
57
58






59
60
61
62
63






64
65
66
67
68






69
70
71
72
73
74
75
}

/*!
 * The scheme part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *scheme;







/*!
 * The host part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host;







/*!
 * The port part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port;

/*!
 * The user part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user;







/*!
 * The password part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password;







/*!
 * The path part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *path;







/*!
 * The path of the URL split into components.
 *
 * The first component must always be empty to designate the root.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFArray OF_GENERIC(OFString *) *pathComponents;







>
>
>
>
>
>





>
>
>
>
>
>










>
>
>
>
>
>





>
>
>
>
>
>





>
>
>
>
>
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
}

/*!
 * The scheme part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *scheme;

/*!
 * The scheme part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedScheme;

/*!
 * The host part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host;

/*!
 * The host part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedHost;

/*!
 * The port part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port;

/*!
 * The user part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user;

/*!
 * The user part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedUser;

/*!
 * The password part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password;

/*!
 * The password part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedPassword;

/*!
 * The path part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *path;

/*!
 * The path part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedPath;

/*!
 * The path of the URL split into components.
 *
 * The first component must always be empty to designate the root.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFArray OF_GENERIC(OFString *) *pathComponents;
83
84
85
86
87
88
89






90
91
92
93
94






95
96
97
98
99
100
101
    OFString *lastPathComponent;

/*!
 * The query part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query;







/*!
 * The fragment part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment;







/*!
 * The URL as a string.
 */
@property (readonly, nonatomic) OFString *string;

/*!
 * The local file system representation for a file URL.







>
>
>
>
>
>





>
>
>
>
>
>







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    OFString *lastPathComponent;

/*!
 * The query part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query;

/*!
 * The query part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedQuery;

/*!
 * The fragment part of the URL.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment;

/*!
 * The fragment part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedFragment;

/*!
 * The URL as a string.
 */
@property (readonly, nonatomic) OFString *string;

/*!
 * The local file system representation for a file URL.

Modified src/OFURL.m from [45850285e0] to [9f39c392cd].

394
395
396
397
398
399
400





401
402
403
404
405





406
407
408
409
410
411
412
413
414
415





416
417
418
419
420





421
422
423
424
425






426
427
428
429
430
431
432
	return hash;
}

- (OFString *)scheme
{
	return _scheme;
}






- (OFString *)host
{
	return _host;
}






- (OFNumber *)port
{
	return _port;
}

- (OFString *)user
{
	return _user;
}






- (OFString *)password
{
	return _password;
}






- (OFString *)path
{
	return _path;
}







- (OFArray *)pathComponents
{
	return [_path componentsSeparatedByString: @"/"];
}

- (OFString *)lastPathComponent







>
>
>
>
>





>
>
>
>
>










>
>
>
>
>





>
>
>
>
>





>
>
>
>
>
>







394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
	return hash;
}

- (OFString *)scheme
{
	return _scheme;
}

- (OFString *)URLEncodedScheme
{
	return [_scheme stringByURLEncoding];
}

- (OFString *)host
{
	return _host;
}

- (OFString *)URLEncodedHost
{
	return [_host stringByURLEncoding];
}

- (OFNumber *)port
{
	return _port;
}

- (OFString *)user
{
	return _user;
}

- (OFString *)URLEncodedUser
{
	return [_user stringByURLEncoding];
}

- (OFString *)password
{
	return _password;
}

- (OFString *)URLEncodedPassword
{
	return [_password stringByURLEncoding];
}

- (OFString *)path
{
	return _path;
}

- (OFString *)URLEncodedPath
{
	return [_path stringByURLEncodingWithAllowedCharacters:
	    "-._~!$&'()*+,;=:@/"];
}

- (OFArray *)pathComponents
{
	return [_path componentsSeparatedByString: @"/"];
}

- (OFString *)lastPathComponent
469
470
471
472
473
474
475






476
477
478
479
480






481
482
483
484
485
486
487
	return [ret autorelease];
}

- (OFString *)query
{
	return _query;
}







- (OFString *)fragment
{
	return _fragment;
}







- (id)copy
{
	return [self retain];
}

- (id)mutableCopy







>
>
>
>
>
>





>
>
>
>
>
>







495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
	return [ret autorelease];
}

- (OFString *)query
{
	return _query;
}

- (OFString *)URLEncodedQuery
{
	return [_query stringByURLEncodingWithAllowedCharacters:
	    "-._~!$&'()*+,;=:@/?"];
}

- (OFString *)fragment
{
	return _fragment;
}

- (OFString *)URLEncodedFragment
{
	return [_fragment stringByURLEncodingWithAllowedCharacters:
	    "-._~!$&'()*+,;=:@/?"];
}

- (id)copy
{
	return [self retain];
}

- (id)mutableCopy
506
507
508
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
542
543
544
545
546
547
548
549
550
551
}

- (OFString *)string
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();

	[ret appendFormat: @"%@://", [_scheme stringByURLEncoding]];

	if (_user != nil && _password != nil)
		[ret appendFormat: @"%@:%@@",
				   [_user stringByURLEncoding],
				   [_password stringByURLEncoding]];
	else if (_user != nil)
		[ret appendFormat: @"%@@", [_user stringByURLEncoding]];

	if (_host != nil)
		[ret appendString: [_host stringByURLEncoding]];
	if (_port != nil)
		[ret appendFormat: @":%@", _port];

	if (_path != nil) {
		if (![_path hasPrefix: @"/"])
			@throw [OFInvalidFormatException exception];

		[ret appendString: [_path
		    stringByURLEncodingWithAllowedCharacters:
		    "-._~!$&'()*+,;=:@/"]];
	}

	if (_query != nil)
		[ret appendFormat: @"?%@",
		    [_query stringByURLEncodingWithAllowedCharacters:
		    "-._~!$&'()*+,;=:@/?"]];

	if (_fragment != nil)
		[ret appendFormat: @"#%@",
		    [_fragment stringByURLEncodingWithAllowedCharacters:
		    "-._~!$&'()*+,;=:@/?"]];

	objc_autoreleasePoolPop(pool);

	[ret makeImmutable];

	return ret;
}







|



|
|

|


|







|
<
<



|
<
<


|
<
<







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569


570
571
572
573


574
575
576


577
578
579
580
581
582
583
}

- (OFString *)string
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();

	[ret appendFormat: @"%@://", [self URLEncodedScheme]];

	if (_user != nil && _password != nil)
		[ret appendFormat: @"%@:%@@",
				   [self URLEncodedUser],
				   [self URLEncodedPassword]];
	else if (_user != nil)
		[ret appendFormat: @"%@@", [self URLEncodedUser]];

	if (_host != nil)
		[ret appendString: [self URLEncodedHost]];
	if (_port != nil)
		[ret appendFormat: @":%@", _port];

	if (_path != nil) {
		if (![_path hasPrefix: @"/"])
			@throw [OFInvalidFormatException exception];

		[ret appendString: [self URLEncodedPath]];


	}

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



	if (_fragment != nil)
		[ret appendFormat: @"#%@", [self URLEncodedFragment]];



	objc_autoreleasePoolPop(pool);

	[ret makeImmutable];

	return ret;
}