mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
* Headers/Foundation/NSXMLElement.h: Change _attributes to be
a NSMutableDictionary instead of an NSMutableArray. * Source/NSXMLElement.m: Change implementation of some methods to use an NSMutableDictionary instead of arrays. Initialize ivars in initializer. * Source/NSXMLPrivate.h: Remove redundant method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34394 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6f2aee3252
commit
3014907a3a
4 changed files with 25 additions and 42 deletions
|
@ -1,3 +1,12 @@
|
|||
2012-01-02 22:26-EST Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Foundation/NSXMLElement.h: Change _attributes to be
|
||||
a NSMutableDictionary instead of an NSMutableArray.
|
||||
* Source/NSXMLElement.m: Change implementation of some methods
|
||||
to use an NSMutableDictionary instead of arrays. Initialize
|
||||
ivars in initializer.
|
||||
* Source/NSXMLPrivate.h: Remove redundant method.
|
||||
|
||||
2012-01-02 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/GSSocketStream.m (-initWithInput:output:): Attempt to
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
@class NSDictionary, NSEnumerator, NSMutableArray;
|
||||
@class NSDictionary, NSEnumerator, NSMutableArray, NSMutableDictionary;
|
||||
|
||||
/**
|
||||
* Represents an XML element.<br />
|
||||
|
@ -42,14 +41,12 @@ extern "C" {
|
|||
{
|
||||
#if GS_EXPOSE(NSXMLElement)
|
||||
@protected
|
||||
// NSString *_name;
|
||||
NSMutableArray *_attributes;
|
||||
NSMutableDictionary *_attributes;
|
||||
NSMutableArray *_namespaces;
|
||||
NSMutableArray *_children;
|
||||
BOOL _childrenHaveMutated;
|
||||
NSString *_URI;
|
||||
NSInteger _prefixIndex;
|
||||
NSString *_value;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -48,13 +48,20 @@
|
|||
if ((self = [super initWithKind:NSXMLElementKind]) != nil)
|
||||
{
|
||||
ASSIGN(_name, name);
|
||||
_attributes = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
||||
_namespaces = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
_children = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
_URI = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithName: (NSString*)name stringValue: (NSString*)string
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
if([self initWithName: name URI: nil] != nil)
|
||||
{
|
||||
[self setObjectValue: string];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -78,24 +85,13 @@
|
|||
|
||||
- (void) addAttribute: (NSXMLNode*)attribute
|
||||
{
|
||||
[_attributes addObject: attribute];
|
||||
[_attributes setObject: attribute
|
||||
forKey: [attribute name]];
|
||||
}
|
||||
|
||||
- (void) removeAttributeForName: (NSString*)name
|
||||
{
|
||||
NSEnumerator *en = [_attributes objectEnumerator];
|
||||
NSXMLNode *node = nil;
|
||||
int index = 0;
|
||||
|
||||
while ((node = [en nextObject]) != nil)
|
||||
{
|
||||
NSString *nodeName = [node name];
|
||||
if ([nodeName isEqualToString: name])
|
||||
{
|
||||
[_attributes removeObjectAtIndex: index];
|
||||
}
|
||||
index++;
|
||||
}
|
||||
[_attributes removeObjectForKey: name];
|
||||
}
|
||||
|
||||
- (void) setAttributes: (NSArray*)attributes
|
||||
|
@ -111,35 +107,17 @@
|
|||
|
||||
- (void) setAttributesAsDictionary: (NSDictionary*)attributes
|
||||
{
|
||||
NSEnumerator *ken = [attributes keyEnumerator];
|
||||
id key = nil;
|
||||
while ((key = [ken nextObject]) != nil)
|
||||
{
|
||||
id value = [attributes objectForKey: key];
|
||||
NSXMLNode *node = [NSXMLNode attributeWithName: key
|
||||
stringValue: value];
|
||||
[self addAttribute: node];
|
||||
}
|
||||
ASSIGN(_attributes, [attributes mutableCopy]);
|
||||
}
|
||||
|
||||
- (NSArray*) attributes
|
||||
{
|
||||
return _attributes;
|
||||
return [_attributes allValues];
|
||||
}
|
||||
|
||||
- (NSXMLNode*) attributeForName: (NSString*)name
|
||||
{
|
||||
NSEnumerator *enumerator = [[self attributes] objectEnumerator];
|
||||
NSXMLNode *attribute;
|
||||
|
||||
while ((attribute = [enumerator nextObject]) != nil)
|
||||
{
|
||||
if ([name isEqualToString: [attribute name]] == YES)
|
||||
{
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
return [_attributes objectForKey: name];
|
||||
}
|
||||
|
||||
- (NSXMLNode*) attributeForLocalName: (NSString*)localName
|
||||
|
|
|
@ -76,6 +76,5 @@
|
|||
#endif
|
||||
|
||||
@interface NSXMLNode (Private)
|
||||
- (void) setName: (NSString *)name;
|
||||
- (void) setParent: (NSXMLNode *)node;
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue