Skip to content

Removing the Warning and Fix null parameters #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions TBXML-Code/TBXML+Compression.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -264,16 +264,16 @@ - (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;
int status;

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;
Expand All @@ -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);
Expand Down
135 changes: 54 additions & 81 deletions TBXML-Code/TBXML.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions TBXML-Support/TBXML-iOS-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,52 @@

#ifdef __OBJC__
#import <Foundation/Foundation.h>

// 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