ObjFW  Check-in [17d18368bb]

Overview
Comment:Change serialization format.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 17d18368bb562cdd6eab8a611adbbd169785cc650b1e3ada85be6f904371e43a
User & Date: js on 2011-05-08 22:36:34
Other Links: manifest | tags
Context
2011-05-08
22:42
Add serialization for OFURL and OFXMLElement. check-in: cb3be92fe6 user: js tags: trunk
22:36
Change serialization format. check-in: 17d18368bb user: js tags: trunk
22:17
Add -[string] to OFURL. check-in: 925754a097 user: js tags: trunk
Changes

Modified src/OFArray.m from [b11d50e081] to [a04fd61311].

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
	OFAutoreleasePool *pool;
	OFMutableString *ret;
	OFObject <OFSerialization> **cArray;
	size_t i, count;

	if ([array count] == 0) {
		if ([self isKindOfClass: [OFMutableArray class]])
			return @"<mutable,0>()";
		else
			return @"<0>()";
	}

	cArray = [array cArray];
	count = [array count];
	if ([self isKindOfClass: [OFMutableArray class]])
		ret = [OFMutableString stringWithFormat: @"<mutable,%zd>(\n",
							 count];
	else
		ret = [OFMutableString stringWithFormat: @"<%zd>(\n", count];
	pool = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count - 1; i++) {
		[ret appendString: [cArray[i] stringBySerializing]];
		[ret appendString: @",\n"];

		[pool releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendFormat: @"%@\n)", [cArray[i] stringBySerializing]];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.







|

|





|


|










|







435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
	OFAutoreleasePool *pool;
	OFMutableString *ret;
	OFObject <OFSerialization> **cArray;
	size_t i, count;

	if ([array count] == 0) {
		if ([self isKindOfClass: [OFMutableArray class]])
			return @"(mutable,0)[]";
		else
			return @"(0)[]";
	}

	cArray = [array cArray];
	count = [array count];
	if ([self isKindOfClass: [OFMutableArray class]])
		ret = [OFMutableString stringWithFormat: @"(mutable,%zd)[\n",
							 count];
	else
		ret = [OFMutableString stringWithFormat: @"(%zd)[\n", count];
	pool = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count - 1; i++) {
		[ret appendString: [cArray[i] stringBySerializing]];
		[ret appendString: @",\n"];

		[pool releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendFormat: @"%@\n]", [cArray[i] stringBySerializing]];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.

Modified src/OFDictionary.m from [894cef5e29] to [167e60e6d6].

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
	OFAutoreleasePool *pool, *pool2;
	OFEnumerator *keyEnumerator, *objectEnumerator;
	id key, object;
	size_t i;

	if (count == 0) {
		if ([self isKindOfClass: [OFMutableDictionary class]])
			return @"<mutable,0>{}";
		else
			return @"<0>{}";
	}

	if ([self isKindOfClass: [OFMutableDictionary class]])
		ret = [OFMutableString stringWithFormat: @"<mutable,%zd>{\n",
							 count];
	else
		ret = [OFMutableString stringWithFormat: @"<%zd>{\n", count];
	pool = [[OFAutoreleasePool alloc] init];
	keyEnumerator = [self keyEnumerator];
	objectEnumerator = [self objectEnumerator];

	i = 0;
	pool2 = [[OFAutoreleasePool alloc] init];

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		[ret appendString: [key stringBySerializing]];
		[ret appendString: @" = "];
		[ret appendString: [object stringBySerializing]];

		if (++i < count)
			[ret appendString: @";\n"];

		[pool2 releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @";\n}"];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.







|

|



|


|














|





|







763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
	OFAutoreleasePool *pool, *pool2;
	OFEnumerator *keyEnumerator, *objectEnumerator;
	id key, object;
	size_t i;

	if (count == 0) {
		if ([self isKindOfClass: [OFMutableDictionary class]])
			return @"(mutable,0){}";
		else
			return @"(0){}";
	}

	if ([self isKindOfClass: [OFMutableDictionary class]])
		ret = [OFMutableString stringWithFormat: @"(mutable,%zd){\n",
							 count];
	else
		ret = [OFMutableString stringWithFormat: @"(%zd){\n", count];
	pool = [[OFAutoreleasePool alloc] init];
	keyEnumerator = [self keyEnumerator];
	objectEnumerator = [self objectEnumerator];

	i = 0;
	pool2 = [[OFAutoreleasePool alloc] init];

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		[ret appendString: [key stringBySerializing]];
		[ret appendString: @" = "];
		[ret appendString: [object stringBySerializing]];

		if (++i < count)
			[ret appendString: @",\n"];

		[pool2 releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @"\n}"];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.

Modified src/OFList.m from [81309c84e2] to [75df3d0578].

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
- (OFString*)stringBySerializing
{
	OFMutableString *ret;
	OFAutoreleasePool *pool;
	of_list_object_t *iter;

	if (count == 0)
		return @"<list,mutable>()";

	ret = [OFMutableString stringWithString: @"<list,mutable>(\n"];
	pool = [[OFAutoreleasePool alloc] init];

	for (iter = firstListObject; iter != NULL; iter = iter->next) {
		[ret appendString: [iter->object stringBySerializing]];

		if (iter->next != NULL)
			[ret appendString: @",\n"];

		[pool releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @"\n)"];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.







|

|












|







326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
- (OFString*)stringBySerializing
{
	OFMutableString *ret;
	OFAutoreleasePool *pool;
	of_list_object_t *iter;

	if (count == 0)
		return @"(list,mutable)[]";

	ret = [OFMutableString stringWithString: @"(list,mutable)[\n"];
	pool = [[OFAutoreleasePool alloc] init];

	for (iter = firstListObject; iter != NULL; iter = iter->next) {
		[ret appendString: [iter->object stringBySerializing]];

		if (iter->next != NULL)
			[ret appendString: @",\n"];

		[pool releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @"\n]"];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.

Modified src/OFString.m from [4009def51f] to [bb52ca9d4f].

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
				       withString: @"\\n\"\n    \""];
	[serialization replaceOccurrencesOfString: @"\r"
				       withString: @"\\r"];
	[serialization replaceOccurrencesOfString: @"\t"
				       withString: @"\\t"];

	if ([self isKindOfClass: [OFMutableString class]])
		[serialization prependString: @"<mutable>\""];
	else
		[serialization prependString: @"\""];
	[serialization appendString: @"\""];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it







|







1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
				       withString: @"\\n\"\n    \""];
	[serialization replaceOccurrencesOfString: @"\r"
				       withString: @"\\r"];
	[serialization replaceOccurrencesOfString: @"\t"
				       withString: @"\\t"];

	if ([self isKindOfClass: [OFMutableString class]])
		[serialization prependString: @"(mutable)\""];
	else
		[serialization prependString: @"\""];
	[serialization appendString: @"\""];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it