448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
else if (parent != nil && parent->_defaultNamespace != nil)
defaultNS = parent->_defaultNamespace;
else
defaultNS = _defaultNamespace;
i = 0;
length = _name.UTF8StringLength + 3 + (level * indentation);
cString = of_alloc(length, 1);
@try {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
/* Start of tag */
cString[i++] = '<';
if (prefix != nil && ![_namespace isEqual: defaultNS]) {
length += prefix.UTF8StringLength + 1;
cString = of_realloc(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength);
i += _name.UTF8StringLength;
/* xmlns if necessary */
if (prefix == nil && ((_namespace != nil &&
![_namespace isEqual: defaultNS]) ||
(_namespace == nil && defaultNS != nil))) {
length += _namespace.UTF8StringLength + 9;
cString = of_realloc(cString, length, 1);
memcpy(cString + i, " xmlns='", 8);
i += 8;
memcpy(cString + i, _namespace.UTF8String,
_namespace.UTF8StringLength);
i += _namespace.UTF8StringLength;
cString[i++] = '\'';
|
|
|
|
|
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
else if (parent != nil && parent->_defaultNamespace != nil)
defaultNS = parent->_defaultNamespace;
else
defaultNS = _defaultNamespace;
i = 0;
length = _name.UTF8StringLength + 3 + (level * indentation);
cString = OFAllocMemory(length, 1);
@try {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
/* Start of tag */
cString[i++] = '<';
if (prefix != nil && ![_namespace isEqual: defaultNS]) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength);
i += _name.UTF8StringLength;
/* xmlns if necessary */
if (prefix == nil && ((_namespace != nil &&
![_namespace isEqual: defaultNS]) ||
(_namespace == nil && defaultNS != nil))) {
length += _namespace.UTF8StringLength + 9;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, " xmlns='", 8);
i += 8;
memcpy(cString + i, _namespace.UTF8String,
_namespace.UTF8StringLength);
i += _namespace.UTF8StringLength;
cString[i++] = '\'';
|
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
@throw [OFUnboundNamespaceException
exceptionWithNamespace: attribute.namespace
element: self];
length += attributeNameLength + (attributePrefix != nil
? attributePrefix.UTF8StringLength + 1 : 0) +
tmp.UTF8StringLength + 4;
cString = of_realloc(cString, length, 1);
cString[i++] = ' ';
if (attributePrefix != nil) {
memcpy(cString + i, attributePrefix.UTF8String,
attributePrefix.UTF8StringLength);
i += attributePrefix.UTF8StringLength;
cString[i++] = ':';
|
|
|
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
@throw [OFUnboundNamespaceException
exceptionWithNamespace: attribute.namespace
element: self];
length += attributeNameLength + (attributePrefix != nil
? attributePrefix.UTF8StringLength + 1 : 0) +
tmp.UTF8StringLength + 4;
cString = OFResizeMemory(cString, length, 1);
cString[i++] = ' ';
if (attributePrefix != nil) {
memcpy(cString + i, attributePrefix.UTF8String,
attributePrefix.UTF8StringLength);
i += attributePrefix.UTF8StringLength;
cString[i++] = ':';
|
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
}
if (indent)
[tmp addItem: "\n"];
length += tmp.count + _name.UTF8StringLength + 2 +
(indent ? level * indentation : 0);
cString = of_realloc(cString, length, 1);
cString[i++] = '>';
memcpy(cString + i, tmp.items, tmp.count);
i += tmp.count;
if (indent) {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
}
cString[i++] = '<';
cString[i++] = '/';
if (prefix != nil) {
length += prefix.UTF8StringLength + 1;
cString = of_realloc(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String,
_name.UTF8StringLength);
i += _name.UTF8StringLength;
} else
cString[i++] = '/';
cString[i++] = '>';
assert(i == length);
objc_autoreleasePoolPop(pool);
ret = [OFString stringWithUTF8String: cString
length: length];
} @finally {
free(cString);
}
return ret;
}
- (OFString *)XMLString
{
return [self of_XMLStringWithParent: nil
|
|
|
|
|
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
}
if (indent)
[tmp addItem: "\n"];
length += tmp.count + _name.UTF8StringLength + 2 +
(indent ? level * indentation : 0);
cString = OFResizeMemory(cString, length, 1);
cString[i++] = '>';
memcpy(cString + i, tmp.items, tmp.count);
i += tmp.count;
if (indent) {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
}
cString[i++] = '<';
cString[i++] = '/';
if (prefix != nil) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String,
_name.UTF8StringLength);
i += _name.UTF8StringLength;
} else
cString[i++] = '/';
cString[i++] = '>';
assert(i == length);
objc_autoreleasePoolPop(pool);
ret = [OFString stringWithUTF8String: cString
length: length];
} @finally {
OFFreeMemory(cString);
}
return ret;
}
- (OFString *)XMLString
{
return [self of_XMLStringWithParent: nil
|