ObjFW  Check-in [e832f884e6]

Overview
Comment:OFIRI: Add -[IRIByDeletingLastPathComponent]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e832f884e6a3e3a9c46a923ab97a6a54491a40f88b8f7238304dbe67d6bbbc01
User & Date: js on 2024-03-10 16:23:56
Other Links: manifest | tags
Context
2024-03-10
16:29
Add a note about ABI stability of ObjFWTest check-in: b60ab363c6 user: js tags: trunk
16:23
OFIRI: Add -[IRIByDeletingLastPathComponent] check-in: e832f884e6 user: js tags: trunk
16:03
Add test for -[OFIRI IRIByAppendingPathComponent:] check-in: 3f3ddad4c8 user: js tags: trunk
Changes

Modified src/OFIRI.h from [d647ebbbce] to [d4857e1b44].

157
158
159
160
161
162
163





164
165
166
167
168
169
170
@property (readonly, nonatomic) OFString *string;

/**
 * @brief The IRI with relative subpaths resolved.
 */
@property (readonly, nonatomic) OFIRI *IRIByStandardizingPath;






/**
 * @brief The IRI with percent-encoding added for all Unicode characters.
 */
@property (readonly, nonatomic)
    OFIRI *IRIByAddingPercentEncodingForUnicodeCharacters;

#ifdef OF_HAVE_FILES







>
>
>
>
>







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@property (readonly, nonatomic) OFString *string;

/**
 * @brief The IRI with relative subpaths resolved.
 */
@property (readonly, nonatomic) OFIRI *IRIByStandardizingPath;

/**
 * @brief The IRI with the last path component deleted.
 */
@property (readonly, nonatomic) OFIRI *IRIByDeletingLastPathComponent;

/**
 * @brief The IRI with percent-encoding added for all Unicode characters.
 */
@property (readonly, nonatomic)
    OFIRI *IRIByAddingPercentEncodingForUnicodeCharacters;

#ifdef OF_HAVE_FILES

Modified src/OFIRI.m from [0bb8a821c7] to [f981acd3b0].

1308
1309
1310
1311
1312
1313
1314








1315
1316
1317
1318
1319
1320
1321
			   isDirectory: (bool)isDirectory
{
	OFMutableIRI *IRI = [[self mutableCopy] autorelease];
	[IRI appendPathComponent: component isDirectory: isDirectory];
	[IRI makeImmutable];
	return IRI;
}









- (OFIRI *)IRIByStandardizingPath
{
	OFMutableIRI *IRI = [[self mutableCopy] autorelease];
	[IRI standardizePath];
	[IRI makeImmutable];
	return IRI;







>
>
>
>
>
>
>
>







1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
			   isDirectory: (bool)isDirectory
{
	OFMutableIRI *IRI = [[self mutableCopy] autorelease];
	[IRI appendPathComponent: component isDirectory: isDirectory];
	[IRI makeImmutable];
	return IRI;
}

- (OFIRI *)IRIByDeletingLastPathComponent
{
	OFMutableIRI *IRI = [[self mutableCopy] autorelease];
	[IRI deleteLastPathComponent];
	[IRI makeImmutable];
	return IRI;
}

- (OFIRI *)IRIByStandardizingPath
{
	OFMutableIRI *IRI = [[self mutableCopy] autorelease];
	[IRI standardizePath];
	[IRI makeImmutable];
	return IRI;

Modified src/OFMutableIRI.h from [ec0dda1233] to [f1d3d3e8dc].

204
205
206
207
208
209
210





211
212
213
214
215
216
217
 * @param component The component to append
 * @param isDirectory Whether the path is a directory, in which case a slash is
 *		      appended if there is no slash yet
 */
- (void)appendPathComponent: (OFString *)component
		isDirectory: (bool)isDirectory;






/**
 * @brief Resolves relative subpaths.
 */
- (void)standardizePath;

/**
 * @brief Converts the mutable IRI to an immutable IRI.







>
>
>
>
>







204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
 * @param component The component to append
 * @param isDirectory Whether the path is a directory, in which case a slash is
 *		      appended if there is no slash yet
 */
- (void)appendPathComponent: (OFString *)component
		isDirectory: (bool)isDirectory;

/**
 * @brief Deletes the last path component.
 */
- (void)deleteLastPathComponent;

/**
 * @brief Resolves relative subpaths.
 */
- (void)standardizePath;

/**
 * @brief Converts the mutable IRI to an immutable IRI.

Modified src/OFMutableIRI.m from [df72f9042f] to [f07aac1192].

370
371
372
373
374
375
376




























377
378
379
380
381
382
383

	if (isDirectory && ![path hasSuffix: @"/"])
		path = [path stringByAppendingString: @"/"];

	[_percentEncodedPath release];
	_percentEncodedPath = [path retain];





























	objc_autoreleasePoolPop(pool);
}

- (void)standardizePath
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray OF_GENERIC(OFString *) *array;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

	if (isDirectory && ![path hasSuffix: @"/"])
		path = [path stringByAppendingString: @"/"];

	[_percentEncodedPath release];
	_percentEncodedPath = [path retain];

	objc_autoreleasePoolPop(pool);
}

- (void)deleteLastPathComponent
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = _percentEncodedPath;
	size_t pos;

	if (path.length == 0 || [path isEqual: @"/"]) {
		objc_autoreleasePoolPop(pool);
		return;
	}

	if ([path hasSuffix: @"/"])
		 path = [path substringToIndex: path.length - 1];

	pos = [path rangeOfString: @"/"
			  options: OFStringSearchBackwards].location;
	if (pos == OFNotFound) {
		objc_autoreleasePoolPop(pool);
		return;
	}

	path = [path substringToIndex: pos + 1];
	[_percentEncodedPath release];
	_percentEncodedPath = [path retain];

	objc_autoreleasePoolPop(pool);
}

- (void)standardizePath
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray OF_GENERIC(OFString *) *array;

Modified tests/OFIRITests.m from [73a758592c] to [287e2de2cf].

353
354
355
356
357
358
359























360
361
362
363
364
365
366

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/path/component/"]
	    IRIByAppendingPathComponent: @"foo/bar"
			    isDirectory: true] path],
	    @"/path/component/foo/bar/");
}
























- (void)testIRIByAddingPercentEncodingForUnicodeCharacters
{
	OTAssertEqualObjects(
	    _IRI[10].IRIByAddingPercentEncodingForUnicodeCharacters,
	    [OFIRI IRIWithString: @"http://%C3%A4/%C3%B6?%C3%BC"]);
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/path/component/"]
	    IRIByAppendingPathComponent: @"foo/bar"
			    isDirectory: true] path],
	    @"/path/component/foo/bar/");
}

- (void)testIRIByDeletingLastPathComponent
{
	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/path/component"]
	    IRIByDeletingLastPathComponent] path], @"/path/");

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/path/directory/"]
	    IRIByDeletingLastPathComponent] path], @"/path/");

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/path"]
	    IRIByDeletingLastPathComponent] path], @"/");

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host/"]
	    IRIByDeletingLastPathComponent] path], @"/");

	OTAssertEqualObjects(
	    [[[OFIRI IRIWithString: @"http://host"]
	    IRIByDeletingLastPathComponent] path], @"");
}

- (void)testIRIByAddingPercentEncodingForUnicodeCharacters
{
	OTAssertEqualObjects(
	    _IRI[10].IRIByAddingPercentEncodingForUnicodeCharacters,
	    [OFIRI IRIWithString: @"http://%C3%A4/%C3%B6?%C3%BC"]);
}