mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 17:51:01 +00:00
* Source/NSXMLDocument.m
* Source/NSXMLElement.m: add code to insertChild:atIndex: to handle edge cases. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34569 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
14ac5c523f
commit
f81a39b90d
3 changed files with 43 additions and 9 deletions
|
@ -1,3 +1,9 @@
|
|||
2012-01-17 18:32-EST Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Source/NSXMLDocument.m
|
||||
* Source/NSXMLElement.m: add code to insertChild:atIndex: to
|
||||
handle edge cases.
|
||||
|
||||
2012-01-17 04:05-EST Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Source/NSXMLElement.m
|
||||
|
|
|
@ -292,12 +292,18 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
{
|
||||
prevNode = nextNode->prev;
|
||||
}
|
||||
else if(index > 0)
|
||||
{
|
||||
prevNode = (xmlNodePtr)[[self childAtIndex: index - 1] _node];
|
||||
}
|
||||
|
||||
// Make all of the links...
|
||||
/*
|
||||
if(prevNode != NULL)
|
||||
{
|
||||
prevNode->next = newNode;
|
||||
prevNode = nextNode;
|
||||
}
|
||||
*/
|
||||
newNode->next = nextNode;
|
||||
newNode->prev = prevNode;
|
||||
if(nextNode != NULL)
|
||||
|
@ -310,6 +316,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
MY_DOC->children = newNode;
|
||||
}
|
||||
|
||||
((xmlNodePtr)[child _node])->parent = [self _node];
|
||||
GSIVar(child, parent) = self;
|
||||
}
|
||||
|
||||
|
|
|
@ -247,8 +247,8 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
|
||||
if(ns)
|
||||
{
|
||||
result = [NSMutableArray array];
|
||||
xmlNsPtr cur = NULL;
|
||||
result = [NSMutableArray array];
|
||||
for(cur = ns; cur != NULL; cur = cur->next)
|
||||
{
|
||||
[result addObject: StringFromXMLStringPtr(cur->prefix)];
|
||||
|
@ -279,17 +279,17 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
|
||||
- (void) insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index
|
||||
{
|
||||
NSXMLNodeKind kind;
|
||||
NSXMLNodeKind kind = [child kind];
|
||||
NSXMLNode *next = nil;
|
||||
xmlNodePtr nextNode = NULL;
|
||||
xmlNodePtr newNode = NULL;
|
||||
xmlNodePtr prevNode = NULL;
|
||||
NSUInteger childCount = [self childCount];
|
||||
|
||||
// Check to make sure this is a valid addition...
|
||||
NSAssert(nil != child, NSInvalidArgumentException);
|
||||
NSAssert(index <= [self childCount], NSInvalidArgumentException);
|
||||
NSAssert(index <= childCount, NSInvalidArgumentException);
|
||||
NSAssert(nil == [child parent], NSInvalidArgumentException);
|
||||
kind = [child kind];
|
||||
NSAssert(NSXMLAttributeKind != kind, NSInvalidArgumentException);
|
||||
NSAssert(NSXMLDTDKind != kind, NSInvalidArgumentException);
|
||||
NSAssert(NSXMLDocumentKind != kind, NSInvalidArgumentException);
|
||||
|
@ -303,14 +303,35 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
newNode = ((xmlNodePtr)[child _node]);
|
||||
next = [self childAtIndex: index];
|
||||
nextNode = ((xmlNodePtr)[next _node]);
|
||||
if(nextNode != NULL)
|
||||
{
|
||||
prevNode = nextNode->prev;
|
||||
}
|
||||
else if(index > 0)
|
||||
{
|
||||
prevNode = (xmlNodePtr)[[self childAtIndex: index - 1] _node];
|
||||
}
|
||||
|
||||
// Make all of the links...
|
||||
prevNode->next = newNode;
|
||||
/*
|
||||
if(prevNode != NULL)
|
||||
{
|
||||
prevNode = nextNode;
|
||||
}
|
||||
*/
|
||||
newNode->next = nextNode;
|
||||
newNode->prev = prevNode;
|
||||
if(nextNode != NULL)
|
||||
{
|
||||
nextNode->prev = newNode;
|
||||
}
|
||||
|
||||
if(MY_NODE->children == NULL)
|
||||
{
|
||||
MY_NODE->children = newNode;
|
||||
}
|
||||
|
||||
((xmlNodePtr)[child _node])->parent = [self _node];
|
||||
GSIVar(child, parent) = self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue