diff --git a/TBXML-Code/TBXML+Compression.m b/TBXML-Code/TBXML+Compression.m index 81b3f63..d27219e 100644 --- a/TBXML-Code/TBXML+Compression.m +++ b/TBXML-Code/TBXML+Compression.m @@ -230,7 +230,7 @@ - (NSData *)gzipDeflate strm.opaque = Z_NULL; strm.total_out = 0; strm.next_in=(Bytef *)[self bytes]; - strm.avail_in = [self length]; + strm.avail_in = (uInt)[self length]; // Compresssion Levels: // Z_NO_COMPRESSION @@ -248,7 +248,7 @@ - (NSData *)gzipDeflate [compressed increaseLengthBy: 16384]; strm.next_out = [compressed mutableBytes] + strm.total_out; - strm.avail_out = [compressed length] - strm.total_out; + strm.avail_out = (uInt)[compressed length] - (uInt)strm.total_out; deflate(&strm, Z_FINISH); @@ -264,8 +264,8 @@ - (NSData *)gzipInflate { if ([self length] == 0) return self; - unsigned full_length = [self length]; - unsigned half_length = [self length] / 2; + unsigned full_length = (uInt)[self length]; + unsigned half_length = (uInt)[self length] / 2; NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; BOOL done = NO; @@ -273,7 +273,7 @@ - (NSData *)gzipInflate z_stream strm; strm.next_in = (Bytef *)[self bytes]; - strm.avail_in = [self length]; + strm.avail_in = (uInt)[self length]; strm.total_out = 0; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -285,7 +285,7 @@ - (NSData *)gzipInflate if (strm.total_out >= [decompressed length]) [decompressed increaseLengthBy: half_length]; strm.next_out = [decompressed mutableBytes] + strm.total_out; - strm.avail_out = [decompressed length] - strm.total_out; + strm.avail_out = (uInt)[decompressed length] - (uInt)strm.total_out; // Inflate another chunk. status = inflate (&strm, Z_SYNC_FLUSH); diff --git a/TBXML-Code/TBXML.m b/TBXML-Code/TBXML.m index b5b1bec..331ff1a 100644 --- a/TBXML-Code/TBXML.m +++ b/TBXML-Code/TBXML.m @@ -240,7 +240,7 @@ - (int) decodeData:(NSData*)data withError:(NSError **)error { if (error) *error = localError; // return success or error code - return localError == nil ? D_TBXML_SUCCESS : [localError code]; + return localError == nil ? D_TBXML_SUCCESS : (int)[localError code]; } @end @@ -256,8 +256,7 @@ - (int) decodeData:(NSData*)data withError:(NSError **)error { @implementation TBXML (StaticFunctions) + (NSString*) elementName:(TBXMLElement*)aXMLElement { - if (nil == aXMLElement->name) return @""; - return [NSString stringWithCString:&aXMLElement->name[0] encoding:NSUTF8StringEncoding]; + return [TBXML elementName:aXMLElement error:nil]; } + (NSString*) elementName:(TBXMLElement*)aXMLElement error:(NSError **)error { @@ -277,8 +276,7 @@ + (NSString*) elementName:(TBXMLElement*)aXMLElement error:(NSError **)error { } + (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute { - if (nil == aXMLAttribute->name) return @""; - return [NSString stringWithCString:&aXMLAttribute->name[0] encoding:NSUTF8StringEncoding]; + return [TBXML attributeValue:aXMLAttribute error:nil]; } + (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute error:(NSError **)error { @@ -299,8 +297,7 @@ + (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute error:(NSError **)err + (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute { - if (nil == aXMLAttribute->value) return @""; - return [NSString stringWithCString:&aXMLAttribute->value[0] encoding:NSUTF8StringEncoding]; + return [TBXML attributeValue:aXMLAttribute error:nil]; } + (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute error:(NSError **)error { @@ -314,8 +311,7 @@ + (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute error:(NSError **)er } + (NSString*) textForElement:(TBXMLElement*)aXMLElement { - if (nil == aXMLElement->text) return @""; - return [NSString stringWithCString:&aXMLElement->text[0] encoding:NSUTF8StringEncoding]; + return [TBXML textForElement:aXMLElement error:nil]; } + (NSString*) textForElement:(TBXMLElement*)aXMLElement error:(NSError **)error { @@ -335,17 +331,7 @@ + (NSString*) textForElement:(TBXMLElement*)aXMLElement error:(NSError **)error } + (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*)aXMLElement { - const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding]; - NSString * value = nil; - TBXMLAttribute * attribute = aXMLElement->firstAttribute; - while (attribute) { - if (strlen(attribute->name) == strlen(name) && memcmp(attribute->name,name,strlen(name)) == 0) { - value = [NSString stringWithCString:&attribute->value[0] encoding:NSUTF8StringEncoding]; - break; - } - attribute = attribute->next; - } - return value; + return [TBXML valueOfAttributeNamed:aName forElement:aXMLElement error:nil]; } + (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*)aXMLElement error:(NSError **)error { @@ -370,7 +356,7 @@ + (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*) if (attribute->value[0]) value = [NSString stringWithCString:&attribute->value[0] encoding:NSUTF8StringEncoding]; else - value = [NSString stringWithString:@""]; + value = @""; break; } @@ -387,16 +373,7 @@ + (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*) } + (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement{ - - TBXMLElement * xmlElement = aParentXMLElement->firstChild; - const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding]; - while (xmlElement) { - if (strlen(xmlElement->name) == strlen(name) && memcmp(xmlElement->name,name,strlen(name)) == 0) { - return xmlElement; - } - xmlElement = xmlElement->nextSibling; - } - return nil; + return [TBXML childElementNamed:aName parentElement:aParentXMLElement error:nil]; } + (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement error:(NSError **)error { @@ -427,15 +404,7 @@ + (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement } + (TBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(TBXMLElement*)aXMLElement{ - TBXMLElement * xmlElement = aXMLElement->nextSibling; - const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding]; - while (xmlElement) { - if (strlen(xmlElement->name) == strlen(name) && memcmp(xmlElement->name,name,strlen(name)) == 0) { - return xmlElement; - } - xmlElement = xmlElement->nextSibling; - } - return nil; + return [TBXML nextSiblingNamed:aName searchFromElement:aXMLElement error:nil]; } + (TBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(TBXMLElement*)aXMLElement error:(NSError **)error { @@ -470,58 +439,62 @@ + (void)iterateElementsForQuery:(NSString *)query fromElement:(TBXMLElement *)an NSArray *components = [query componentsSeparatedByString:@"."]; TBXMLElement *currTBXMLElement = anElement; - // navigate down - for (NSInteger i=0; i < components.count; ++i) { - NSString *iTagName = [components objectAtIndex:i]; - - if ([iTagName isEqualToString:@"*"]) { - currTBXMLElement = currTBXMLElement->firstChild; + if (currTBXMLElement) { + // navigate down + for (NSInteger i=0; i < components.count; ++i) { + NSString *iTagName = [components objectAtIndex:i]; - // different behavior depending on if this is the end of the query or midstream - if (i < (components.count - 1)) { - // midstream - do { - NSString *restOfQuery = [[components subarrayWithRange:NSMakeRange(i + 1, components.count - i - 1)] componentsJoinedByString:@"."]; - [TBXML iterateElementsForQuery:restOfQuery fromElement:currTBXMLElement withBlock:iterateBlock]; - } while ((currTBXMLElement = currTBXMLElement->nextSibling)); + if ([iTagName isEqualToString:@"*"]) { + currTBXMLElement = currTBXMLElement->firstChild; + // different behavior depending on if this is the end of the query or midstream + if (i < (components.count - 1)) { + // midstream + do { + NSString *restOfQuery = [[components subarrayWithRange:NSMakeRange(i + 1, components.count - i - 1)] componentsJoinedByString:@"."]; + [TBXML iterateElementsForQuery:restOfQuery fromElement:currTBXMLElement withBlock:iterateBlock]; + } while ((currTBXMLElement = currTBXMLElement->nextSibling)); + + } + } else { + currTBXMLElement = [TBXML childElementNamed:iTagName parentElement:currTBXMLElement]; + } + + if (!currTBXMLElement) { + break; } - } else { - currTBXMLElement = [TBXML childElementNamed:iTagName parentElement:currTBXMLElement]; - } - - if (!currTBXMLElement) { - break; } - } - - if (currTBXMLElement) { - // enumerate - NSString *childTagName = [components lastObject]; - if ([childTagName isEqualToString:@"*"]) { - childTagName = nil; + if (currTBXMLElement) { + // enumerate + NSString *childTagName = [components lastObject]; + + if ([childTagName isEqualToString:@"*"]) { + childTagName = nil; + } + + do { + iterateBlock(currTBXMLElement); + } while (childTagName ? (currTBXMLElement = [TBXML nextSiblingNamed:childTagName searchFromElement:currTBXMLElement]) : (currTBXMLElement = currTBXMLElement->nextSibling)); } - - do { - iterateBlock(currTBXMLElement); - } while (childTagName ? (currTBXMLElement = [TBXML nextSiblingNamed:childTagName searchFromElement:currTBXMLElement]) : (currTBXMLElement = currTBXMLElement->nextSibling)); } } + (void)iterateAttributesOfElement:(TBXMLElement *)anElement withBlock:(TBXMLIterateAttributeBlock)iterateAttributeBlock { - - // Obtain first attribute from element - TBXMLAttribute * attribute = anElement->firstAttribute; - - // if attribute is valid - while (attribute) { - // Call the iterateAttributeBlock with the attribute, it's name and value - iterateAttributeBlock(attribute, [TBXML attributeName:attribute], [TBXML attributeValue:attribute]); + if (anElement) { + // Obtain first attribute from element + TBXMLAttribute * attribute = anElement->firstAttribute; - // Obtain the next attribute - attribute = attribute->next; + // if attribute is valid + + while (attribute) { + // Call the iterateAttributeBlock with the attribute, it's name and value + iterateAttributeBlock(attribute, [TBXML attributeName:attribute], [TBXML attributeValue:attribute]); + + // Obtain the next attribute + attribute = attribute->next; + } } } @@ -597,7 +570,7 @@ - (int) allocateBytesOfLength:(long)length error:(NSError **)error { if (error) *error = localError; - return localError == nil ? D_TBXML_SUCCESS : [localError code]; + return localError == nil ? D_TBXML_SUCCESS : (int)[localError code]; } - (void) decodeBytes { diff --git a/TBXML-Support/TBXML-iOS-Prefix.pch b/TBXML-Support/TBXML-iOS-Prefix.pch index 88c8f1e..0f8c6e5 100644 --- a/TBXML-Support/TBXML-iOS-Prefix.pch +++ b/TBXML-Support/TBXML-iOS-Prefix.pch @@ -4,4 +4,52 @@ #ifdef __OBJC__ #import + + // define some LLVM3 macros if the code is compiled with a different compiler (ie LLVMGCC42) + #ifndef __has_feature + #define __has_feature(x) 0 + #endif + + #ifndef __has_extension + #define __has_extension __has_feature // Compatibility with pre-3.0 compilers. + #endif + + #if __has_feature(objc_arc) && __clang_major__ >= 3 + #define ARC_ENABLED 1 + #endif // __has_feature(objc_arc) + + + // not using clang LLVM compiler, or LLVM version is not 3.x + #if !defined(__clang__) || __clang_major__ < 3 + + #ifndef __bridge + #define __bridge + #endif + + #ifndef __bridge_retained + #define __bridge_retained + #endif + + #ifndef __bridge_transfer + #define __bridge_transfer + #endif + + #ifndef __autoreleasing + #define __autoreleasing + #endif + + #ifndef __strong + #define __strong + #endif + + #ifndef __weak + #define __weak + #endif + + #ifndef __unsafe_unretained + #define __unsafe_unretained + #endif + + #endif // __clang_major__ < 3 + #endif