@@ -50,25 +50,25 @@ static Class CDATAClass = Nil; @interface OFXMLElement_OFXMLElementBuilderDelegate: OFObject { @public - OFXMLElement *element; + OFXMLElement *_element; } @end @implementation OFXMLElement_OFXMLElementBuilderDelegate - (void)elementBuilder: (OFXMLElementBuilder*)builder - didBuildElement: (OFXMLElement*)element_ + didBuildElement: (OFXMLElement*)element { - if (element == nil) - element = [element_ retain]; + if (_element == nil) + _element = [element retain]; } - (void)dealloc { - [element release]; + [_element release]; [super dealloc]; } @end @@ -134,49 +134,49 @@ } abort(); } -- initWithName: (OFString*)name_ +- initWithName: (OFString*)name { - return [self initWithName: name_ + return [self initWithName: name namespace: nil stringValue: nil]; } -- initWithName: (OFString*)name_ +- initWithName: (OFString*)name stringValue: (OFString*)stringValue { - return [self initWithName: name_ + return [self initWithName: name namespace: nil stringValue: stringValue]; } -- initWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- initWithName: (OFString*)name + namespace: (OFString*)namespace { - return [self initWithName: name_ - namespace: ns_ + return [self initWithName: name + namespace: namespace stringValue: nil]; } -- initWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- initWithName: (OFString*)name + namespace: (OFString*)namespace stringValue: (OFString*)stringValue { self = [super init]; @try { - if (name_ == nil) + if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [name_ copy]; - ns = [ns_ copy]; + _name = [name copy]; + _namespace = [namespace copy]; - namespaces = [[OFMutableDictionary alloc] + _namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: @"http://www.w3.org/XML/1998/namespace", @"xml", @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; if (stringValue != nil) @@ -197,16 +197,16 @@ if (element == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [element->name copy]; - ns = [element->ns copy]; - defaultNamespace = [element->defaultNamespace copy]; - attributes = [element->attributes mutableCopy]; - namespaces = [element->namespaces mutableCopy]; - children = [element->children mutableCopy]; + _name = [element->_name copy]; + _namespace = [element->_namespace copy]; + _defaultNamespace = [element->_defaultNamespace copy]; + _attributes = [element->_attributes mutableCopy]; + _namespaces = [element->_namespaces mutableCopy]; + _children = [element->_children mutableCopy]; } @catch (id e) { [self release]; @throw e; } @@ -242,11 +242,11 @@ if (![parser finishedParsing]) @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; - self = [delegate->element retain]; + self = [delegate->_element retain]; objc_autoreleasePoolPop(pool); return self; } @@ -276,11 +276,11 @@ if (![parser finishedParsing]) @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; - self = [delegate->element retain]; + self = [delegate->_element retain]; objc_autoreleasePoolPop(pool); return self; } @@ -300,14 +300,15 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [[[element attributeForName: @"name"] stringValue] copy]; - ns = [[[element attributeForName: @"namespace"] stringValue] - copy]; - defaultNamespace = [[[element attributeForName: + _name = [[[element attributeForName: @"name"] + stringValue] copy]; + _namespace = [[[element attributeForName: @"namespace"] + stringValue] copy]; + _defaultNamespace = [[[element attributeForName: @"defaultNamespace"] stringValue] copy]; attributesElement = [[[element elementForName: @"attributes" namespace: OF_SERIALIZATION_NS] elementsForNamespace: @@ -319,61 +320,61 @@ childrenElement = [[[element elementForName: @"children" namespace: OF_SERIALIZATION_NS] elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; - attributes = [[attributesElement objectByDeserializing] + _attributes = [[attributesElement objectByDeserializing] mutableCopy]; - namespaces = [[namespacesElement objectByDeserializing] + _namespaces = [[namespacesElement objectByDeserializing] mutableCopy]; - children = [[childrenElement objectByDeserializing] + _children = [[childrenElement objectByDeserializing] mutableCopy]; /* Sanity checks */ - if ((attributes != nil && - ![attributes isKindOfClass: [OFMutableArray class]]) || - (namespaces != nil && - ![namespaces isKindOfClass: [OFMutableDictionary class]]) || - (children != nil && - ![children isKindOfClass: [OFMutableArray class]])) + if ((_attributes != nil && ![_attributes isKindOfClass: + [OFMutableArray class]]) || (_namespaces != nil && + ![_namespaces isKindOfClass: + [OFMutableDictionary class]]) || (_children != nil && + ![_children isKindOfClass: [OFMutableArray class]])) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - objectEnumerator = [attributes objectEnumerator]; + objectEnumerator = [_attributes objectEnumerator]; while ((object = [objectEnumerator nextObject]) != nil) if (![object isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - keyEnumerator = [namespaces keyEnumerator]; - objectEnumerator = [namespaces objectEnumerator]; + keyEnumerator = [_namespaces keyEnumerator]; + objectEnumerator = [_namespaces objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) if (![key isKindOfClass: [OFString class]] || ![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - objectEnumerator = [children objectEnumerator]; + objectEnumerator = [_children objectEnumerator]; while ((object = [objectEnumerator nextObject]) != nil) if (![object isKindOfClass: [OFXMLNode class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (namespaces == nil) - namespaces = [[OFMutableDictionary alloc] init]; - - [namespaces setObject: @"xml" - forKey: @"http://www.w3.org/XML/1998/namespace"]; - [namespaces setObject: @"xmlns" - forKey: @"http://www.w3.org/2000/xmlns/"]; - - if (name == nil) + if (_namespaces == nil) + _namespaces = [[OFMutableDictionary alloc] init]; + + [_namespaces + setObject: @"xml" + forKey: @"http://www.w3.org/XML/1998/namespace"]; + [_namespaces setObject: @"xmlns" + forKey: @"http://www.w3.org/2000/xmlns/"]; + + if (_name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; objc_autoreleasePoolPop(pool); @@ -383,48 +384,60 @@ } return self; } -- (void)setName: (OFString*)name_ +- (void)dealloc +{ + [_name release]; + [_namespace release]; + [_defaultNamespace release]; + [_attributes release]; + [_namespaces release]; + [_children release]; + + [super dealloc]; +} + +- (void)setName: (OFString*)name { - if (name_ == nil) + if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } -- (void)setNamespace: (OFString*)ns_ +- (void)setNamespace: (OFString*)namespace { - OF_SETTER(ns, ns_, YES, 1) + OF_SETTER(_namespace, namespace, YES, 1) } - (OFString*)namespace { - OF_GETTER(ns, YES) + OF_GETTER(_namespace, YES) } - (OFArray*)attributes { - OF_GETTER(attributes, YES) + OF_GETTER(_attributes, YES) } -- (void)setChildren: (OFArray*)children_ +- (void)setChildren: (OFArray*)children { - OF_SETTER(children, children_, YES, 2) + OF_SETTER(_children, children, YES, 2) } - (OFArray*)children { - OF_GETTER(children, YES) + OF_GETTER(_children, YES) } - (void)setStringValue: (OFString*)stringValue { void *pool = objc_autoreleasePoolPush(); @@ -437,17 +450,17 @@ - (OFString*)stringValue { OFMutableString *ret; OFXMLElement **objects; - size_t i, count = [children count]; + size_t i, count = [_children count]; if (count == 0) return @""; ret = [OFMutableString string]; - objects = [children objects]; + objects = [_children objects]; for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [objects[i] stringValue]]; @@ -474,16 +487,17 @@ OFString *defaultNS; pool = objc_autoreleasePoolPush(); parentPrefix = [allNamespaces objectForKey: - (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")]; + (parent != nil && parent->_namespace != nil + ? parent->_namespace : (OFString*)@"")]; /* Add the namespaces of the current element */ if (allNamespaces != nil) { - OFEnumerator *keyEnumerator = [namespaces keyEnumerator]; - OFEnumerator *objectEnumerator = [namespaces objectEnumerator]; + OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; + OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; id key, object; tmp = [[allNamespaces mutableCopy] autorelease]; @@ -492,33 +506,33 @@ [tmp setObject: object forKey: key]; allNamespaces = tmp; } else - allNamespaces = namespaces; + allNamespaces = _namespaces; prefix = [allNamespaces objectForKey: - (ns != nil ? ns : (OFString*)@"")]; + (_namespace != nil ? _namespace : (OFString*)@"")]; - if (parent != nil && parent->ns != nil && parentPrefix == nil) - defaultNS = parent->ns; - else if (parent != nil && parent->defaultNamespace != nil) - defaultNS = parent->defaultNamespace; + if (parent != nil && parent->_namespace != nil && parentPrefix == nil) + defaultNS = parent->_namespace; + else if (parent != nil && parent->_defaultNamespace != nil) + defaultNS = parent->_defaultNamespace; else - defaultNS = defaultNamespace; + defaultNS = _defaultNamespace; i = 0; - length = [name UTF8StringLength] + 3 + (level * indentation); + length = [_name UTF8StringLength] + 3 + (level * indentation); cString = [self allocMemoryWithSize: length]; memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; - if (prefix != nil && ![ns isEqual: defaultNS]) { + if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { @@ -530,17 +544,18 @@ [prefix UTF8StringLength]); i += [prefix UTF8StringLength]; cString[i++] = ':'; } - memcpy(cString + i, [name UTF8String], [name UTF8StringLength]); - i += [name UTF8StringLength]; + memcpy(cString + i, [_name UTF8String], [_name UTF8StringLength]); + i += [_name UTF8StringLength]; /* xmlns if necessary */ - if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) || - (ns == nil && defaultNS != nil))) { - length += [ns UTF8StringLength] + 9; + if (prefix == nil && ((_namespace != nil && + ![_namespace isEqual: defaultNS]) || + (_namespace == nil && defaultNS != nil))) { + length += [_namespace UTF8StringLength] + 9; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @@ -547,18 +562,19 @@ @throw e; } memcpy(cString + i, " xmlns='", 8); i += 8; - memcpy(cString + i, [ns UTF8String], [ns UTF8StringLength]); - i += [ns UTF8StringLength]; + memcpy(cString + i, [_namespace UTF8String], + [_namespace UTF8StringLength]); + i += [_namespace UTF8StringLength]; cString[i++] = '\''; } /* Attributes */ - attributesObjects = [attributes objects]; - attributesCount = [attributes count]; + attributesObjects = [_attributes objects]; + attributesCount = [_attributes count]; for (j = 0; j < attributesCount; j++) { void *pool2 = objc_autoreleasePoolPush(); OFString *attributeName = [attributesObjects[j] name]; OFString *attributePrefix = nil; @@ -604,13 +620,13 @@ objc_autoreleasePoolPop(pool2); } /* Childen */ - if (children != nil) { - OFXMLElement **childrenObjects = [children objects]; - size_t childrenCount = [children count]; + if (_children != nil) { + OFXMLElement **childrenObjects = [_children objects]; + size_t childrenCount = [_children count]; OFDataArray *tmp = [OFDataArray dataArray]; BOOL indent; if (indentation > 0) { indent = YES; @@ -650,11 +666,11 @@ } if (indent) [tmp addItem: "\n"]; - length += [tmp count] + [name UTF8StringLength] + 2 + + length += [tmp count] + [_name UTF8StringLength] + 2 + (indent ? level * indentation : 0); @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { @@ -687,12 +703,13 @@ memcpy(cString + i, [prefix UTF8String], [prefix UTF8StringLength]); i += [prefix UTF8StringLength]; cString[i++] = ':'; } - memcpy(cString + i, [name UTF8String], [name UTF8StringLength]); - i += [name UTF8StringLength]; + memcpy(cString + i, [_name UTF8String], + [_name UTF8StringLength]); + i += [_name UTF8StringLength]; } else cString[i++] = '/'; cString[i++] = '>'; assert(i == length); @@ -739,37 +756,37 @@ OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - if (name != nil) + if (_name != nil) [element addAttributeWithName: @"name" - stringValue: name]; + stringValue: _name]; - if (ns != nil) + if (_namespace != nil) [element addAttributeWithName: @"namespace" - stringValue: ns]; + stringValue: _namespace]; - if (defaultNamespace != nil) + if (_defaultNamespace != nil) [element addAttributeWithName: @"defaultNamespace" - stringValue: defaultNamespace]; + stringValue: _defaultNamespace]; - if (attributes != nil) { + if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" namespace: OF_SERIALIZATION_NS]; [attributesElement addChild: - [attributes XMLElementBySerializing]]; + [_attributes XMLElementBySerializing]]; [element addChild: attributesElement]; } - if (namespaces != nil) { + if (_namespaces != nil) { OFXMLElement *namespacesElement; OFMutableDictionary *namespacesCopy = - [[namespaces mutableCopy] autorelease]; + [[_namespaces mutableCopy] autorelease]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/XML/1998/namespace"]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/2000/xmlns/"]; @@ -782,17 +799,17 @@ [namespacesCopy XMLElementBySerializing]]; [element addChild: namespacesElement]; } } - if (children != nil) { + if (_children != nil) { OFXMLElement *childrenElement; childrenElement = [OFXMLElement elementWithName: @"children" namespace: OF_SERIALIZATION_NS]; - [childrenElement addChild: [children XMLElementBySerializing]]; + [childrenElement addChild: [_children XMLElementBySerializing]]; [element addChild: childrenElement]; } [element retain]; @@ -801,47 +818,47 @@ return [element autorelease]; } - (void)addAttribute: (OFXMLAttribute*)attribute { - if (attributes == nil) - attributes = [[OFMutableArray alloc] init]; + if (_attributes == nil) + _attributes = [[OFMutableArray alloc] init]; - if ([self attributeForName: attribute->name - namespace: attribute->ns] == nil) - [attributes addObject: attribute]; + if ([self attributeForName: attribute->_name + namespace: attribute->_namespace] == nil) + [_attributes addObject: attribute]; } -- (void)addAttributeWithName: (OFString*)name_ +- (void)addAttributeWithName: (OFString*)name stringValue: (OFString*)stringValue { - [self addAttributeWithName: name_ + [self addAttributeWithName: name namespace: nil stringValue: stringValue]; } -- (void)addAttributeWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- (void)addAttributeWithName: (OFString*)name + namespace: (OFString*)namespace stringValue: (OFString*)stringValue { void *pool = objc_autoreleasePoolPush(); - [self addAttribute: [OFXMLAttribute attributeWithName: name_ - namespace: ns_ + [self addAttribute: [OFXMLAttribute attributeWithName: name + namespace: namespace stringValue: stringValue]]; objc_autoreleasePoolPop(pool); } - (OFXMLAttribute*)attributeForName: (OFString*)attributeName { - OFXMLAttribute **objects = [attributes objects]; - size_t i, count = [attributes count]; + OFXMLAttribute **objects = [_attributes objects]; + size_t i, count = [_attributes count]; for (i = 0; i < count; i++) - if (objects[i]->ns == nil && - [objects[i]->name isEqual: attributeName]) + if (objects[i]->_namespace == nil && + [objects[i]->_name isEqual: attributeName]) return [[objects[i] retain] autorelease]; return nil; } @@ -852,30 +869,30 @@ size_t i, count; if (attributeNS == nil) return [self attributeForName: attributeName]; - objects = [attributes objects]; - count = [attributes count]; + objects = [_attributes objects]; + count = [_attributes count]; for (i = 0; i < count; i++) - if ([objects[i]->ns isEqual: attributeNS] && - [objects[i]->name isEqual: attributeName]) + if ([objects[i]->_namespace isEqual: attributeNS] && + [objects[i]->_name isEqual: attributeName]) return [[objects[i] retain] autorelease]; return nil; } - (void)removeAttributeForName: (OFString*)attributeName { - OFXMLAttribute **objects = [attributes objects]; - size_t i, count = [attributes count]; + OFXMLAttribute **objects = [_attributes objects]; + size_t i, count = [_attributes count]; for (i = 0; i < count; i++) { - if (objects[i]->ns == nil && - [objects[i]->name isEqual: attributeName]) { - [attributes removeObjectAtIndex: i]; + if (objects[i]->_namespace == nil && + [objects[i]->_name isEqual: attributeName]) { + [_attributes removeObjectAtIndex: i]; return; } } } @@ -887,67 +904,67 @@ size_t i, count; if (attributeNS == nil) return [self removeAttributeForName: attributeName]; - objects = [attributes objects]; - count = [attributes count]; + objects = [_attributes objects]; + count = [_attributes count]; for (i = 0; i < count; i++) { - if ([objects[i]->ns isEqual: attributeNS] && - [objects[i]->name isEqual: attributeName]) { - [attributes removeObjectAtIndex: i]; + if ([objects[i]->_namespace isEqual: attributeNS] && + [objects[i]->_name isEqual: attributeName]) { + [_attributes removeObjectAtIndex: i]; return; } } } - (void)setPrefix: (OFString*)prefix - forNamespace: (OFString*)ns_ + forNamespace: (OFString*)namespace { if ([prefix length] == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (ns_ == nil) - ns_ = @""; + if (namespace == nil) + namespace = @""; - [namespaces setObject: prefix - forKey: ns_]; + [_namespaces setObject: prefix + forKey: namespace]; } - (void)bindPrefix: (OFString*)prefix - forNamespace: (OFString*)ns_ + forNamespace: (OFString*)namespace { [self setPrefix: prefix - forNamespace: ns_]; + forNamespace: namespace]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" - stringValue: ns_]; + stringValue: namespace]; } - (OFString*)defaultNamespace { - OF_GETTER(defaultNamespace, YES) + OF_GETTER(_defaultNamespace, YES) } -- (void)setDefaultNamespace: (OFString*)ns_ +- (void)setDefaultNamespace: (OFString*)defaultNamespace { - OF_SETTER(defaultNamespace, ns_, YES, 1) + OF_SETTER(_defaultNamespace, defaultNamespace, YES, 1) } - (void)addChild: (OFXMLNode*)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (children == nil) - children = [[OFMutableArray alloc] init]; + if (_children == nil) + _children = [[OFMutableArray alloc] init]; - [children addObject: child]; + [_children addObject: child]; } - (void)insertChild: (OFXMLNode*)child atIndex: (size_t)index { @@ -954,32 +971,32 @@ if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (children == nil) - children = [[OFMutableArray alloc] init]; + if (_children == nil) + _children = [[OFMutableArray alloc] init]; - [children insertObject: child - atIndex: index]; + [_children insertObject: child + atIndex: index]; } -- (void)insertChildren: (OFArray*)children_ +- (void)insertChildren: (OFArray*)children atIndex: (size_t)index { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [children_ objectEnumerator]; + OFEnumerator *enumerator = [children objectEnumerator]; OFXMLNode *node; while ((node = [enumerator nextObject]) != nil) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children insertObjectsFromArray: children_ - atIndex: index]; + [_children insertObjectsFromArray: children + atIndex: index]; objc_autoreleasePoolPop(pool); } - (void)removeChild: (OFXMLNode*)child @@ -987,16 +1004,16 @@ if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children removeObject: child]; + [_children removeObject: child]; } - (void)removeChildAtIndex: (size_t)index { - [children removeObjectAtIndex: index]; + [_children removeObjectAtIndex: index]; } - (void)replaceChild: (OFXMLNode*)child withNode: (OFXMLNode*)node { @@ -1004,12 +1021,12 @@ [child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children replaceObject: child - withObject: node]; + [_children replaceObject: child + withObject: node]; } - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode*)node { @@ -1016,12 +1033,12 @@ if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children replaceObjectAtIndex: index - withObject: node]; + [_children replaceObjectAtIndex: index + withObject: node]; } - (OFXMLElement*)elementForName: (OFString*)elementName { return [[self elementsForName: elementName] firstObject]; @@ -1035,12 +1052,12 @@ } - (OFArray*)elements { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]]) [ret addObject: objects[i]]; @@ -1050,17 +1067,17 @@ } - (OFArray*)elementsForName: (OFString*)elementName { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->ns == nil && - [objects[i]->name isEqual: elementName]) + objects[i]->_namespace == nil && + [objects[i]->_name isEqual: elementName]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; @@ -1067,17 +1084,17 @@ } - (OFArray*)elementsForNamespace: (OFString*)elementNS { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->name != nil && - [objects[i]->ns isEqual: elementNS]) + objects[i]->_name != nil && + [objects[i]->_namespace isEqual: elementNS]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; @@ -1092,48 +1109,49 @@ if (elementNS == nil) return [self elementsForName: elementName]; ret = [OFMutableArray array]; - objects = [children objects]; - count = [children count]; + objects = [_children objects]; + count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - [objects[i]->ns isEqual: elementNS] && - [objects[i]->name isEqual: elementName]) + [objects[i]->_namespace isEqual: elementNS] && + [objects[i]->_name isEqual: elementName]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; } - (BOOL)isEqual: (id)object { - OFXMLElement *otherElement; + OFXMLElement *element; if (![object isKindOfClass: [OFXMLElement class]]) return NO; - otherElement = object; - - if (otherElement->name != name && ![otherElement->name isEqual: name]) - return NO; - if (otherElement->ns != ns && ![otherElement->ns isEqual: ns]) - return NO; - if (otherElement->defaultNamespace != defaultNamespace && - ![otherElement->defaultNamespace isEqual: defaultNamespace]) - return NO; - if (otherElement->attributes != attributes && - ![otherElement->attributes isEqual: attributes]) - return NO; - if (otherElement->namespaces != namespaces && - ![otherElement->namespaces isEqual: namespaces]) - return NO; - if (otherElement->children != children && - ![otherElement->children isEqual: children]) + element = object; + + if (element->_name != _name && ![element->_name isEqual: _name]) + return NO; + if (element->_namespace != _namespace && + ![element->_namespace isEqual: _namespace]) + return NO; + if (element->_defaultNamespace != _defaultNamespace && + ![element->_defaultNamespace isEqual: _defaultNamespace]) + return NO; + if (element->_attributes != _attributes && + ![element->_attributes isEqual: _attributes]) + return NO; + if (element->_namespaces != _namespaces && + ![element->_namespaces isEqual: _namespaces]) + return NO; + if (element->_children != _children && + ![element->_children isEqual: _children]) return NO; return YES; } @@ -1141,16 +1159,16 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [name hash]); - OF_HASH_ADD_HASH(hash, [ns hash]); - OF_HASH_ADD_HASH(hash, [defaultNamespace hash]); - OF_HASH_ADD_HASH(hash, [attributes hash]); - OF_HASH_ADD_HASH(hash, [namespaces hash]); - OF_HASH_ADD_HASH(hash, [children hash]); + OF_HASH_ADD_HASH(hash, [_name hash]); + OF_HASH_ADD_HASH(hash, [_namespace hash]); + OF_HASH_ADD_HASH(hash, [_defaultNamespace hash]); + OF_HASH_ADD_HASH(hash, [_attributes hash]); + OF_HASH_ADD_HASH(hash, [_namespaces hash]); + OF_HASH_ADD_HASH(hash, [_children hash]); OF_HASH_FINALIZE(hash); return hash; } @@ -1157,18 +1175,6 @@ - copy { return [[[self class] alloc] initWithElement: self]; } - -- (void)dealloc -{ - [name release]; - [ns release]; - [defaultNamespace release]; - [attributes release]; - [namespaces release]; - [children release]; - - [super dealloc]; -} @end