ObjFW  Diff

Differences From Artifact [6fd40e1ec7]:

To Artifact [2e27de79cd]:

  • File src/OFXMLElement.m — part of check-in [21bd46e17a] at 2011-05-14 20:00:48 on branch 0.5 — Fix namespace handling in OFXMLElement.

    Although it was originally decided not to backport this to 0.5, the
    decision was changed due to the fact that the initial assumption that
    it might break existing code is only partially true: It will only break
    code that already was broken, but it will fix all other code. (user: js, size: 16988) [annotate] [blame] [check-ins using]


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
390
391
392
393
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
		 * -[copy] is called.
		 */
		str->isa = [OFString class];
		return str;
	}

	pool = [[OFAutoreleasePool alloc] init];
	def_ns = (defaultNamespace != nil
	    ? defaultNamespace
	    : (parent != nil ? parent->defaultNamespace : (OFString*)nil));

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

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

		while ((key = [key_enum nextObject]) != nil &&
		    (obj = [obj_enum nextObject]) != nil)
			[all_namespaces setObject: obj
					   forKey: key];
	} 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*)@"")];








	i = 0;
	len = [name cStringLength] + 3;
	str_c = [self allocMemoryWithSize: len];

	/* Start of tag */
	str_c[i++] = '<';

	if (prefix != nil && ![ns isEqual: def_ns] &&
	    (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] ||
	    parent_prefix != nil)) {
		len += [prefix cStringLength] + 1;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
			[self freeMemory: str_c];
			@throw e;
		}

		memcpy(str_c + i, [prefix cString],
		    [prefix cStringLength]);
		i += [prefix cStringLength];
		str_c[i++] = ':';
	}

	memcpy(str_c + i, [name cString], [name cStringLength]);
	i += [name cStringLength];

	/* xmlns if necessary */
	if (ns != nil && prefix == nil && ![ns isEqual: def_ns] &&
	     (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] ||
	     parent_prefix != nil)) {
		len += [ns cStringLength] + 9;

		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
			[self freeMemory: str_c];
			@throw e;
		}

		memcpy(str_c + i, " xmlns='", 8);
		i += 8;
		memcpy(str_c + i, [ns cString], [ns cStringLength]);
		i += [ns cStringLength];
		str_c[i++] = '\'';

		def_ns = ns;
	}

	/* Attributes */
	attrs_carray = [attributes cArray];
	attrs_count = [attributes count];

	pool2 = [[OFAutoreleasePool alloc] init];







<
<
<




















>
>
>
>
>
>
>







|
<
<



















|
<
|















<
<







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
390
391
392
393
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
		 * -[copy] is called.
		 */
		str->isa = [OFString class];
		return str;
	}

	pool = [[OFAutoreleasePool alloc] init];




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

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

		while ((key = [key_enum nextObject]) != nil &&
		    (obj = [obj_enum nextObject]) != nil)
			[all_namespaces setObject: obj
					   forKey: key];
	} 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;

	i = 0;
	len = [name cStringLength] + 3;
	str_c = [self allocMemoryWithSize: len];

	/* Start of tag */
	str_c[i++] = '<';

	if (prefix != nil && ![ns isEqual: def_ns]) {


		len += [prefix cStringLength] + 1;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
			[self freeMemory: str_c];
			@throw e;
		}

		memcpy(str_c + i, [prefix cString],
		    [prefix cStringLength]);
		i += [prefix cStringLength];
		str_c[i++] = ':';
	}

	memcpy(str_c + i, [name cString], [name cStringLength]);
	i += [name cStringLength];

	/* xmlns if necessary */
	if (prefix == nil && ((ns != nil && ![ns isEqual: def_ns]) ||

	    (ns == nil && def_ns != nil))) {
		len += [ns cStringLength] + 9;

		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (id e) {
			[self freeMemory: str_c];
			@throw e;
		}

		memcpy(str_c + i, " xmlns='", 8);
		i += 8;
		memcpy(str_c + i, [ns cString], [ns cStringLength]);
		i += [ns cStringLength];
		str_c[i++] = '\'';


	}

	/* Attributes */
	attrs_carray = [attributes cArray];
	attrs_count = [attributes count];

	pool2 = [[OFAutoreleasePool alloc] init];