ObjFW  Check-in [55599756ab]

Overview
Comment:Fix handling of nested namespaces in OFXMLElement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.5
Files: files | file ages | folders
SHA3-256: 55599756ab0a0e9002608fa2d0c998de60e5e4c7b2c93e74b234afc9ae16e9b3
User & Date: js on 2011-09-06 11:42:51
Other Links: branch diff | manifest | tags
Context
2012-02-20
22:43
Close 0.5 branch, as it is no longer maintained. Closed-Leaf check-in: 1512d853e7 user: js tags: 0.5
2011-09-06
11:42
Fix handling of nested namespaces in OFXMLElement. check-in: 55599756ab user: js tags: 0.5
2011-08-30
16:29
Update the ChangeLog for 0.5.4. check-in: 282011d842 user: js tags: 0.5, 0.5.4-release
Changes

Modified src/OFXMLElement.m from [648374ef15] to [dc999e1b97].

333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354







+







-







	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

- (OFString*)_XMLStringWithParent: (OFXMLElement*)parent
		       namespaces: (OFDictionary*)all_namespaces
{
	OFAutoreleasePool *pool, *pool2;
	char *str_c;
	size_t len, i, j, attrs_count;
	OFString *prefix, *parent_prefix;
	OFXMLAttribute **attrs_carray;
	OFString *ret, *tmp;
	OFMutableDictionary *all_namespaces;
	OFString *def_ns;

	if (characters != nil)
		return [characters stringByXMLEscaping];

	if (cdata != nil)
		return [OFString stringWithFormat: @"<![CDATA[%@]]>", cdata];
368
369
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
368
369
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







+
+
+
-
+


+


-
+



-
-
+
+
+
+





-
-







		 */
		str->isa = [OFString class];
		return str;
	}

	pool = [[OFAutoreleasePool alloc] init];

	parent_prefix = [all_namespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];

	if (parent != nil && parent->namespaces != nil) {
	if (all_namespaces != nil) {
		OFEnumerator *key_enum = [namespaces keyEnumerator];
		OFEnumerator *obj_enum = [namespaces objectEnumerator];
		OFMutableDictionary *mutable;
		id key, obj;

		all_namespaces = [[parent->namespaces mutableCopy] autorelease];
		mutable = [[all_namespaces mutableCopy] autorelease];

		while ((key = [key_enum nextObject]) != nil &&
		    (obj = [obj_enum nextObject]) != nil)
			[all_namespaces setObject: obj
					   forKey: key];
			[mutable setObject: obj
				    forKey: key];

		all_namespaces = mutable;
	} else
		all_namespaces = namespaces;

	prefix = [all_namespaces objectForKey:
	    (ns != nil ? ns : (OFString*)@"")];
	parent_prefix = [all_namespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];

	if (parent != nil && parent->ns != nil && parent_prefix == nil)
		def_ns = parent->ns;
	else if (parent != nil && parent->defaultNamespace != nil)
		def_ns = parent->defaultNamespace;
	else
		def_ns = defaultNamespace;
502
503
504
505
506
507
508
509


510
511
512
513
514
515
516
506
507
508
509
510
511
512

513
514
515
516
517
518
519
520
521







-
+
+







		append = [tmp methodForSelector:
		    @selector(appendCStringWithoutUTF8Checking:)];

		for (j = 0; j < children_count; j++)
			append(tmp, @selector(
			    appendCStringWithoutUTF8Checking:),
			    [[children_carray[j]
			    _XMLStringWithParent: self] cString]);
			    _XMLStringWithParent: self
				      namespaces: all_namespaces] cString]);

		len += [tmp cStringLength] + [name cStringLength] + 2;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
			[self freeMemory: str_c];
554
555
556
557
558
559
560
561


562
563
564
565
566
567
568
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573
574







-
+
+







		[self freeMemory: str_c];
	}
	return ret;
}

- (OFString*)XMLString
{
	return [self _XMLStringWithParent: nil];
	return [self _XMLStringWithParent: nil
			       namespaces: nil];
}

- (OFString*)description
{
	return [self XMLString];
}