ObjFW  Check-in [2fafde4058]

Overview
Comment:Add -[OFDictionary stringByURLEncoding]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2fafde4058f49a1f4476cfcd28d084118941a5fa0bd9aeeb0bc6e28fab85a6df
User & Date: js on 2017-06-25 17:13:29
Other Links: manifest | tags
Context
2017-06-25
17:33
configure: Fix a missing [ check-in: 6d18dda5b1 user: js tags: trunk
17:13
Add -[OFDictionary stringByURLEncoding] check-in: 2fafde4058 user: js tags: trunk
17:08
OFDictionaryTests: Clean up variable names check-in: f8d89b56f2 user: js tags: trunk
Changes

Modified src/OFDictionary.h from [5975df7964] to [cf57ae790d].

253
254
255
256
257
258
259







260
261
262
263
264
265
266
/*!
 * @brief Returns an array of all objects.
 *
 * @return An array of all objects
 */
- (OFArray OF_GENERIC(ObjectType) *)allObjects;








/*!
 * @brief Returns an OFEnumerator to enumerate through the dictionary's keys.
 *
 * @return An OFEnumerator to enumerate through the dictionary's keys
 */
- (OFEnumerator OF_GENERIC(KeyType) *)keyEnumerator;








>
>
>
>
>
>
>







253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*!
 * @brief Returns an array of all objects.
 *
 * @return An array of all objects
 */
- (OFArray OF_GENERIC(ObjectType) *)allObjects;

/*!
 * @brief Creates a string by URL-encoding the contents of the dictionary.
 *
 * @return A URL-encoded string with the contents of the dictionary
 */
- (OFString *)stringByURLEncoding;

/*!
 * @brief Returns an OFEnumerator to enumerate through the dictionary's keys.
 *
 * @return An OFEnumerator to enumerate through the dictionary's keys
 */
- (OFEnumerator OF_GENERIC(KeyType) *)keyEnumerator;

Modified src/OFDictionary.m from [d620b3bd51] to [3fca05019c].

558
559
560
561
562
563
564




























565
566
567
568
569
570
571
			[ret appendString: @";\n"];

		objc_autoreleasePoolPop(pool2);
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @";\n}"];





























	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}







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







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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
			[ret appendString: @";\n"];

		objc_autoreleasePoolPop(pool2);
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @";\n}"];

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (OFString *)stringByURLEncoding
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();
	OFEnumerator *keyEnumerator = [self keyEnumerator];
	OFEnumerator *objectEnumerator = [self objectEnumerator];
	bool first = true;
	id key, object;

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		if OF_UNLIKELY (first)
			first = false;
		else
			[ret appendString: @"&"];

		[ret appendString: [[key description] stringByURLEncoding]];
		[ret appendString: @"="];
		[ret appendString: [[object description] stringByURLEncoding]];
	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

Modified tests/OFDictionaryTests.m from [37eb73f85e] to [76bc88ef2a].

257
258
259
260
261
262
263





264
265
266
267
268
269
270
		ok = true;
	}

	TEST(@"Detection of mutation during Fast Enumeration", ok)

	[mutDict removeObjectForKey: @""];






#ifdef OF_HAVE_BLOCKS
	{
		__block size_t i = 0;
		__block bool ok = true;

		[mutDict enumerateKeysAndObjectsUsingBlock:
		    ^ (id key, id obj, bool *stop) {







>
>
>
>
>







257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
		ok = true;
	}

	TEST(@"Detection of mutation during Fast Enumeration", ok)

	[mutDict removeObjectForKey: @""];

	TEST(@"-[stringByURLEncoding]",
	    [[[OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
							  @"q&x", @"q=x", nil]
	    stringByURLEncoding] isEqual: @"q%26x=q%3Dx&foo=bar"])

#ifdef OF_HAVE_BLOCKS
	{
		__block size_t i = 0;
		__block bool ok = true;

		[mutDict enumerateKeysAndObjectsUsingBlock:
		    ^ (id key, id obj, bool *stop) {