mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
* ChangeLog
* Source/NSXMLDocument.m * Source/NSXMLElement.m * Source/NSXMLNode.m: Implement copyWithZone:, correct issues with previous revert. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34428 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
dd3807023e
commit
a3d5150a84
4 changed files with 89 additions and 17 deletions
|
@ -1,3 +1,11 @@
|
|||
2012-01-05 21:33-EST Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* ChangeLog
|
||||
* Source/NSXMLDocument.m
|
||||
* Source/NSXMLElement.m
|
||||
* Source/NSXMLNode.m: Implement copyWithZone:, correct issues
|
||||
with previous revert.
|
||||
|
||||
2012-01-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSXMLDocument.m:
|
||||
|
|
|
@ -31,6 +31,17 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
|
||||
#import <Foundation/NSXMLParser.h>
|
||||
|
||||
@interface NSXMLDocument (Debug)
|
||||
- (id) elementStack;
|
||||
@end
|
||||
|
||||
@implementation NSXMLDocument (Debug)
|
||||
- (id) elementStack
|
||||
{
|
||||
return internal->elementStack;
|
||||
}
|
||||
@end
|
||||
|
||||
// Forward declaration of interface for NSXMLParserDelegate
|
||||
@interface NSXMLDocument (NSXMLParserDelegate)
|
||||
@end
|
||||
|
@ -112,16 +123,15 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
{
|
||||
NSXMLParser *parser = [[NSXMLParser alloc] initWithData: data];
|
||||
|
||||
internal->standalone = YES;
|
||||
internal->elementStack = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
ASSIGN(internal->xmlData, data);
|
||||
if (nil == parser)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
internal->standalone = YES;
|
||||
internal->elementStack
|
||||
= [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
ASSIGN(internal->xmlData, data);
|
||||
[parser setDelegate: self];
|
||||
[parser parse];
|
||||
RELEASE(parser);
|
||||
|
@ -287,10 +297,12 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
return [self XMLDataWithOptions: NSXMLNodeOptionsNone];
|
||||
}
|
||||
|
||||
- (NSData*) XMLDataWithOptions: (NSUInteger)options
|
||||
- (NSData *) XMLDataWithOptions: (NSUInteger)options
|
||||
{
|
||||
// TODO: Apply options to data.
|
||||
return internal->xmlData;
|
||||
NSString *xmlString = [self XMLStringWithOptions: options];
|
||||
NSData *data = [NSData dataWithBytes: [xmlString UTF8String]
|
||||
length: [xmlString length]];
|
||||
return data;
|
||||
}
|
||||
|
||||
- (NSString *) XMLStringWithOptions: (NSUInteger)options
|
||||
|
@ -343,6 +355,16 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
id c = [super copyWithZone: zone];
|
||||
[c setStandalone: internal->standalone];
|
||||
[c setRootElement: internal->rootElement];
|
||||
[c setDTD: internal->docType];
|
||||
[c setMIMEType: internal->MIMEType];
|
||||
return c;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSXMLDocument (NSXMLParserDelegate)
|
||||
|
|
|
@ -74,6 +74,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
ASSIGN(internal->name, name);
|
||||
internal->attributes = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
||||
internal->namespaces = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
internal->children = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -160,7 +161,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) addNamespace: (NSXMLNode*)aNamespace
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
[internal->namespaces addObject: aNamespace];
|
||||
}
|
||||
|
||||
- (void) removeNamespaceForPrefix: (NSString*)name
|
||||
|
@ -170,15 +171,11 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) setNamespaces: (NSArray*)namespaces
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
ASSIGNCOPY(internal->namespaces, namespaces);
|
||||
}
|
||||
|
||||
- (NSArray*) namespaces
|
||||
{
|
||||
if (internal->namespaces == nil)
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
return internal->namespaces;
|
||||
}
|
||||
|
||||
|
@ -202,7 +199,9 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
[child setParent: self];
|
||||
[internal->children insertObject: child
|
||||
atIndex: index];
|
||||
}
|
||||
|
||||
- (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index
|
||||
|
@ -223,10 +222,16 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) setChildren: (NSArray*)children
|
||||
{
|
||||
NSMutableArray *c = [children mutableCopy];
|
||||
NSMutableArray *c = [children mutableCopy];
|
||||
NSEnumerator *en = [c objectEnumerator];
|
||||
NSXMLNode *n = nil;
|
||||
|
||||
ASSIGN(internal->children, c);
|
||||
[c release];
|
||||
while((n = [en nextObject]) != nil)
|
||||
{
|
||||
[n setParent: self];
|
||||
}
|
||||
// internal->childrenHaveMutated = YES;
|
||||
}
|
||||
|
||||
|
@ -284,5 +289,31 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
return result;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
id c = [super copyWithZone: zone];
|
||||
NSEnumerator *en = [internal->namespaces objectEnumerator];
|
||||
id obj = nil;
|
||||
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
[c addNamespace: [obj copyWithZone: zone]];
|
||||
}
|
||||
|
||||
en = [internal->attributes objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
NSXMLNode *attr = [obj copyWithZone: zone];
|
||||
[c addAttribute: attr];
|
||||
}
|
||||
|
||||
en = [[self children] objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
NSXMLNode *n = [obj copyWithZone:zone];
|
||||
[self addChild: n];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -206,15 +206,26 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
id c = [[self class] allocWithZone: zone];
|
||||
id c = [[self class] allocWithZone: zone];
|
||||
// NSEnumerator *en = [internal->children objectEnumerator];
|
||||
// id obj = nil;
|
||||
|
||||
c = [c initWithKind: internal->kind options: internal->options];
|
||||
[c setName: [self name]];
|
||||
[c setURI: [self URI]];
|
||||
[c setObjectValue: [self objectValue]];
|
||||
[c setStringValue: [self stringValue]];
|
||||
|
||||
/*
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
NSXMLNode *n = [obj copyWithZone:zone];
|
||||
[self addChild: n];
|
||||
}
|
||||
*/
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue