mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
fa365da6de
commit
0d998a3394
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>
|
2012-01-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSXMLDocument.m:
|
* Source/NSXMLDocument.m:
|
||||||
|
|
|
@ -31,6 +31,17 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
||||||
|
|
||||||
#import <Foundation/NSXMLParser.h>
|
#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
|
// Forward declaration of interface for NSXMLParserDelegate
|
||||||
@interface NSXMLDocument (NSXMLParserDelegate)
|
@interface NSXMLDocument (NSXMLParserDelegate)
|
||||||
@end
|
@end
|
||||||
|
@ -112,16 +123,15 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
||||||
{
|
{
|
||||||
NSXMLParser *parser = [[NSXMLParser alloc] initWithData: data];
|
NSXMLParser *parser = [[NSXMLParser alloc] initWithData: data];
|
||||||
|
|
||||||
|
internal->standalone = YES;
|
||||||
|
internal->elementStack = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
|
ASSIGN(internal->xmlData, data);
|
||||||
if (nil == parser)
|
if (nil == parser)
|
||||||
{
|
{
|
||||||
DESTROY(self);
|
DESTROY(self);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
internal->standalone = YES;
|
|
||||||
internal->elementStack
|
|
||||||
= [[NSMutableArray alloc] initWithCapacity: 10];
|
|
||||||
ASSIGN(internal->xmlData, data);
|
|
||||||
[parser setDelegate: self];
|
[parser setDelegate: self];
|
||||||
[parser parse];
|
[parser parse];
|
||||||
RELEASE(parser);
|
RELEASE(parser);
|
||||||
|
@ -287,10 +297,12 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
||||||
return [self XMLDataWithOptions: NSXMLNodeOptionsNone];
|
return [self XMLDataWithOptions: NSXMLNodeOptionsNone];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData*) XMLDataWithOptions: (NSUInteger)options
|
- (NSData *) XMLDataWithOptions: (NSUInteger)options
|
||||||
{
|
{
|
||||||
// TODO: Apply options to data.
|
NSString *xmlString = [self XMLStringWithOptions: options];
|
||||||
return internal->xmlData;
|
NSData *data = [NSData dataWithBytes: [xmlString UTF8String]
|
||||||
|
length: [xmlString length]];
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) XMLStringWithOptions: (NSUInteger)options
|
- (NSString *) XMLStringWithOptions: (NSUInteger)options
|
||||||
|
@ -343,6 +355,16 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
||||||
return NO;
|
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
|
@end
|
||||||
|
|
||||||
@implementation NSXMLDocument (NSXMLParserDelegate)
|
@implementation NSXMLDocument (NSXMLParserDelegate)
|
||||||
|
|
|
@ -74,6 +74,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
ASSIGN(internal->name, name);
|
ASSIGN(internal->name, name);
|
||||||
internal->attributes = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
internal->attributes = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
||||||
internal->namespaces = [[NSMutableArray alloc] initWithCapacity: 10];
|
internal->namespaces = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
|
internal->children = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +161,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
|
|
||||||
- (void) addNamespace: (NSXMLNode*)aNamespace
|
- (void) addNamespace: (NSXMLNode*)aNamespace
|
||||||
{
|
{
|
||||||
[self notImplemented: _cmd];
|
[internal->namespaces addObject: aNamespace];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeNamespaceForPrefix: (NSString*)name
|
- (void) removeNamespaceForPrefix: (NSString*)name
|
||||||
|
@ -170,15 +171,11 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
|
|
||||||
- (void) setNamespaces: (NSArray*)namespaces
|
- (void) setNamespaces: (NSArray*)namespaces
|
||||||
{
|
{
|
||||||
[self notImplemented: _cmd];
|
ASSIGNCOPY(internal->namespaces, namespaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) namespaces
|
- (NSArray*) namespaces
|
||||||
{
|
{
|
||||||
if (internal->namespaces == nil)
|
|
||||||
{
|
|
||||||
[self notImplemented: _cmd];
|
|
||||||
}
|
|
||||||
return internal->namespaces;
|
return internal->namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +199,9 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
|
|
||||||
- (void) insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index
|
- (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
|
- (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index
|
||||||
|
@ -223,10 +222,16 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
|
|
||||||
- (void) setChildren: (NSArray*)children
|
- (void) setChildren: (NSArray*)children
|
||||||
{
|
{
|
||||||
NSMutableArray *c = [children mutableCopy];
|
NSMutableArray *c = [children mutableCopy];
|
||||||
|
NSEnumerator *en = [c objectEnumerator];
|
||||||
|
NSXMLNode *n = nil;
|
||||||
|
|
||||||
ASSIGN(internal->children, c);
|
ASSIGN(internal->children, c);
|
||||||
[c release];
|
[c release];
|
||||||
|
while((n = [en nextObject]) != nil)
|
||||||
|
{
|
||||||
|
[n setParent: self];
|
||||||
|
}
|
||||||
// internal->childrenHaveMutated = YES;
|
// internal->childrenHaveMutated = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,5 +289,31 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
||||||
return result;
|
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
|
@end
|
||||||
|
|
||||||
|
|
|
@ -206,15 +206,26 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
- (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 = [c initWithKind: internal->kind options: internal->options];
|
||||||
[c setName: [self name]];
|
[c setName: [self name]];
|
||||||
[c setURI: [self URI]];
|
[c setURI: [self URI]];
|
||||||
[c setObjectValue: [self objectValue]];
|
[c setObjectValue: [self objectValue]];
|
||||||
[c setStringValue: [self stringValue]];
|
[c setStringValue: [self stringValue]];
|
||||||
|
|
||||||
|
/*
|
||||||
|
while((obj = [en nextObject]) != nil)
|
||||||
|
{
|
||||||
|
NSXMLNode *n = [obj copyWithZone:zone];
|
||||||
|
[self addChild: n];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue