@@ -123,13 +123,11 @@ OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { - return [self initWithName: name - namespace: nil - stringValue: nil]; + return [self initWithName: name namespace: nil stringValue: nil]; } - (instancetype)initWithName: (OFString *)name stringValue: (OFString *)stringValue { @@ -139,13 +137,11 @@ } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { - return [self initWithName: name - namespace: namespace - stringValue: nil]; + return [self initWithName: name namespace: namespace stringValue: nil]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue @@ -210,11 +206,11 @@ @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; - builder = [OFXMLElementBuilder elementBuilder]; + builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; @@ -241,11 +237,11 @@ [self release]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; - builder = [OFXMLElementBuilder elementBuilder]; + builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; @@ -272,11 +268,11 @@ OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _name = [[element attributeForName: @"name"].stringValue copy]; _namespace = [[element attributeForName: @"namespace"] .stringValue copy]; @@ -283,20 +279,20 @@ _defaultNamespace = [[element attributeForName: @"defaultNamespace"].stringValue copy]; attributesElement = [[element elementForName: @"attributes" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; namespacesElement = [[element elementForName: @"namespaces" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; childrenElement = [[element elementForName: @"children" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; _attributes = [attributesElement.objectByDeserializing mutableCopy]; _namespaces = [namespacesElement.objectByDeserializing mutableCopy]; @@ -436,12 +432,11 @@ tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) - [tmp setObject: object - forKey: key]; + [tmp setObject: object forKey: key]; allNS = tmp; } else allNS = _namespaces; @@ -455,11 +450,11 @@ else defaultNS = _defaultNamespace; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); - cString = of_alloc(length, 1); + cString = OFAllocMemory(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; @@ -466,11 +461,11 @@ /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += prefix.UTF8StringLength + 1; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; @@ -482,11 +477,11 @@ /* xmlns if necessary */ if (prefix == nil && ((_namespace != nil && ![_namespace isEqual: defaultNS]) || (_namespace == nil && defaultNS != nil))) { length += _namespace.UTF8StringLength + 9; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); @@ -515,11 +510,11 @@ element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); cString[i++] = ' '; if (attributePrefix != nil) { memcpy(cString + i, attributePrefix.UTF8String, attributePrefix.UTF8StringLength); @@ -585,11 +580,11 @@ if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); cString[i++] = '>'; memcpy(cString + i, tmp.items, tmp.count); i += tmp.count; @@ -601,11 +596,11 @@ cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += prefix.UTF8StringLength + 1; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; @@ -622,11 +617,11 @@ objc_autoreleasePoolPop(pool); ret = [OFString stringWithUTF8String: cString length: length]; } @finally { - free(cString); + OFFreeMemory(cString); } return ret; } - (OFString *)XMLString @@ -658,15 +653,14 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; if (_name != nil) - [element addAttributeWithName: @"name" - stringValue: _name]; + [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) [element addAttributeWithName: @"namespace" stringValue: _namespace]; @@ -677,11 +671,11 @@ if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [attributesElement addChild: _attributes.XMLElementBySerializing]; [element addChild: attributesElement]; } @@ -696,11 +690,11 @@ @"http://www.w3.org/2000/xmlns/"]; if (namespacesCopy.count > 0) { namespacesElement = [OFXMLElement elementWithName: @"namespaces" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [namespacesElement addChild: namespacesCopy.XMLElementBySerializing]; [element addChild: namespacesElement]; } } @@ -708,11 +702,11 @@ if (_children != nil) { OFXMLElement *childrenElement; childrenElement = [OFXMLElement elementWithName: @"children" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [childrenElement addChild: _children.XMLElementBySerializing]; [element addChild: childrenElement]; } [element retain]; @@ -816,27 +810,23 @@ return; } } } -- (void)setPrefix: (OFString *)prefix - forNamespace: (OFString *)namespace +- (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { if (prefix.length == 0) @throw [OFInvalidArgumentException exception]; if (namespace == nil) namespace = @""; - [_namespaces setObject: prefix - forKey: namespace]; + [_namespaces setObject: prefix forKey: namespace]; } -- (void)bindPrefix: (OFString *)prefix - forNamespace: (OFString *)namespace +- (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { - [self setPrefix: prefix - forNamespace: namespace]; + [self setPrefix: prefix forNamespace: namespace]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" stringValue: namespace]; } @@ -849,32 +839,28 @@ _children = [[OFMutableArray alloc] init]; [_children addObject: child]; } -- (void)insertChild: (OFXMLNode *)child - atIndex: (size_t)idx +- (void)insertChild: (OFXMLNode *)child atIndex: (size_t)idx { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_children == nil) _children = [[OFMutableArray alloc] init]; - [_children insertObject: child - atIndex: idx]; + [_children insertObject: child atIndex: idx]; } -- (void)insertChildren: (OFArray *)children - atIndex: (size_t)idx +- (void)insertChildren: (OFArray *)children atIndex: (size_t)idx { for (OFXMLNode *node in children) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; - [_children insertObjectsFromArray: children - atIndex: idx]; + [_children insertObjectsFromArray: children atIndex: idx]; } - (void)removeChild: (OFXMLNode *)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @@ -886,29 +872,25 @@ - (void)removeChildAtIndex: (size_t)idx { [_children removeObjectAtIndex: idx]; } -- (void)replaceChild: (OFXMLNode *)child - withNode: (OFXMLNode *)node +- (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]] || [child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; - [_children replaceObject: child - withObject: node]; + [_children replaceObject: child withObject: node]; } -- (void)replaceChildAtIndex: (size_t)idx - withNode: (OFXMLNode *)node +- (void)replaceChildAtIndex: (size_t)idx withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; - [_children replaceObjectAtIndex: idx - withObject: node]; + [_children replaceObjectAtIndex: idx withObject: node]; } - (OFXMLElement *)elementForName: (OFString *)elementName { return [self elementsForName: elementName].firstObject; @@ -1030,26 +1012,26 @@ return true; } - (unsigned long)hash { - uint32_t hash; - - OF_HASH_INIT(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); + unsigned long hash; + + OFHashInit(&hash); + + OFHashAddHash(&hash, _name.hash); + OFHashAddHash(&hash, _namespace.hash); + OFHashAddHash(&hash, _defaultNamespace.hash); + OFHashAddHash(&hash, _attributes.hash); + OFHashAddHash(&hash, _namespaces.hash); + OFHashAddHash(&hash, _children.hash); + + OFHashFinalize(&hash); return hash; } - (id)copy { return [[[self class] alloc] initWithElement: self]; } @end