Skip to content

Commit

Permalink
Be strict with types
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed Apr 10, 2012
1 parent 9179199 commit 90e188f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
12 changes: 12 additions & 0 deletions RaptureXML.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,16 @@
0DEB8EBD1467EC9B00024989 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
DSTROOT = /tmp/RaptureXML.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Library-Prefix.pch";
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -366,10 +372,16 @@
0DEB8EBE1467EC9B00024989 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
DSTROOT = /tmp/RaptureXML.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Library-Prefix.pch";
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
8 changes: 4 additions & 4 deletions RaptureXML/RXMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
- (NSString *)attribute:(NSString *)attName;
- (NSString *)attribute:(NSString *)attName inNamespace:(NSString *)namespace;

- (NSInteger)attributeAsInt:(NSString *)attName;
- (NSInteger)attributeAsInt:(NSString *)attName inNamespace:(NSString *)namespace;
- (NSInteger)attributeAsInteger:(NSString *)attName;
- (NSInteger)attributeAsInteger:(NSString *)attName inNamespace:(NSString *)namespace;

- (double)attributeAsDouble:(NSString *)attName;
- (double)attributeAsDouble:(NSString *)attName inNamespace:(NSString *)namespace;
Expand All @@ -68,9 +68,9 @@

@property (nonatomic, readonly) NSString *tag;
@property (nonatomic, readonly) NSString *text;
@property (nonatomic, readonly) NSInteger textAsInt;
@property (nonatomic, readonly) NSInteger textAsInteger;
@property (nonatomic, readonly) double textAsDouble;
@property (nonatomic, readonly) BOOL isValid;
@property (nonatomic, readonly, getter = isValid) BOOL valid;

@end

Expand Down
24 changes: 12 additions & 12 deletions RaptureXML/RXMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (id)initFromXMLString:(NSString *)xmlString withEncoding:(NSStringEncoding)enc
if ((self = [super init])) {
NSData *data = [xmlString dataUsingEncoding:encoding];

doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
doc_ = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_RECOVER);

if ([self isValid]) {
node_ = xmlDocGetRootElement(doc_);
Expand All @@ -58,7 +58,7 @@ - (id)initFromXMLFile:(NSString *)filename {
NSString *fullPath = [[[NSBundle bundleForClass:self.class] bundlePath] stringByAppendingPathComponent:filename];
NSData *data = [NSData dataWithContentsOfFile:fullPath];

doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
doc_ = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_RECOVER);

if ([self isValid]) {
node_ = xmlDocGetRootElement(doc_);
Expand All @@ -77,7 +77,7 @@ - (id)initFromXMLFile:(NSString *)filename fileExtension:(NSString *)extension {
NSString *fullPath = [[NSBundle bundleForClass:[self class]] pathForResource:filename ofType:extension];
NSData *data = [NSData dataWithContentsOfFile:fullPath];

doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
doc_ = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_RECOVER);

if ([self isValid]) {
node_ = xmlDocGetRootElement(doc_);
Expand All @@ -95,7 +95,7 @@ - (id)initFromURL:(NSURL *)url {
if ((self = [super init])) {
NSData *data = [NSData dataWithContentsOfURL:url];

doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
doc_ = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_RECOVER);

if ([self isValid]) {
node_ = xmlDocGetRootElement(doc_);
Expand All @@ -111,7 +111,7 @@ - (id)initFromURL:(NSURL *)url {

- (id)initFromXMLData:(NSData *)data {
if ((self = [super init])) {
doc_ = xmlReadMemory([data bytes], [data length], "", nil, XML_PARSE_RECOVER);
doc_ = xmlReadMemory([data bytes], (int)[data length], "", nil, XML_PARSE_RECOVER);

if ([self isValid]) {
node_ = xmlDocGetRootElement(doc_);
Expand Down Expand Up @@ -182,8 +182,8 @@ - (NSString *)text {
return text;
}

- (NSInteger)textAsInt {
return [self.text intValue];
- (NSInteger)textAsInteger {
return [self.text integerValue];
}

- (double)textAsDouble {
Expand All @@ -210,11 +210,11 @@ - (NSString *)attribute:(NSString *)attName inNamespace:(NSString *)namespace {
return nil;
}

- (NSInteger)attributeAsInt:(NSString *)attName {
- (NSInteger)attributeAsInteger:(NSString *)attName {
return [[self attribute:attName] intValue];
}

- (NSInteger)attributeAsInt:(NSString *)attName inNamespace:(NSString *)namespace {
- (NSInteger)attributeAsInteger:(NSString *)attName inNamespace:(NSString *)namespace {
return [[self attribute:attName inNamespace:namespace] intValue];
}

Expand All @@ -237,7 +237,7 @@ - (RXMLElement *)child:(NSString *)tagName {
xmlNodePtr cur = node_;

// navigate down
for (NSInteger i=0; i < components.count; ++i) {
for (NSUInteger i=0; i < components.count; ++i) {
NSString *iTagName = [components objectAtIndex:i];
const xmlChar *tagNameC = (const xmlChar *)[iTagName cStringUsingEncoding:NSUTF8StringEncoding];

Expand Down Expand Up @@ -276,7 +276,7 @@ - (RXMLElement *)child:(NSString *)tagName inNamespace:(NSString *)namespace {
const xmlChar *namespaceC = (const xmlChar *)[namespace cStringUsingEncoding:NSUTF8StringEncoding];

// navigate down
for (NSInteger i=0; i < components.count; ++i) {
for (NSUInteger i=0; i < components.count; ++i) {
NSString *iTagName = [components objectAtIndex:i];
const xmlChar *tagNameC = (const xmlChar *)[iTagName cStringUsingEncoding:NSUTF8StringEncoding];

Expand Down Expand Up @@ -349,7 +349,7 @@ - (void)iterate:(NSString *)query with:(void (^)(RXMLElement *))blk {
xmlNodePtr cur = node_;

// navigate down
for (NSInteger i=0; i < components.count; ++i) {
for (NSUInteger i=0; i < components.count; ++i) {
NSString *iTagName = [components objectAtIndex:i];

if ([iTagName isEqualToString:@"*"]) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BoundaryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (void)testNamespaceAttribute {
RXMLElement *rxml = [RXMLElement elementFromXMLString:namespaceXML_ withEncoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEqualObjects([rxml attribute:@"foo" inNamespace:@"*"], @"bar", nil);
STAssertEquals([rxml attributeAsInt:@"one" inNamespace:@"*"], 1, nil);
STAssertEquals([rxml attributeAsInteger:@"one" inNamespace:@"*"], 1, nil);
}

- (void)testChild {
Expand Down
4 changes: 2 additions & 2 deletions Tests/DeepChildrenTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (void)testDeepChildQuery {
// count the players
RXMLElement *coachingYears = [rxml child:@"players.coach.experience.years"];

STAssertEquals(coachingYears.textAsInt, 1, nil);
STAssertEquals(coachingYears.textAsInteger, 1, nil);
}

- (void)testDeepChildQueryWithWildcard {
Expand All @@ -48,7 +48,7 @@ - (void)testDeepChildQueryWithWildcard {
RXMLElement *coachingYears = [rxml child:@"players.coach.experience.teams.*"];

// first team returned
STAssertEquals(coachingYears.textAsInt, 53, nil);
STAssertEquals(coachingYears.textAsInteger, 53, nil);
}

@end
6 changes: 3 additions & 3 deletions Tests/TextConversionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)testIntTags {

[rxml iterate:@"*" with:^(RXMLElement *e) {
if (i == 0) {
STAssertEquals([e child:@"id"].textAsInt, 1, nil);
STAssertEquals([e child:@"id"].textAsInteger, 1, nil);
} else if (i == 1) {
STAssertEqualsWithAccuracy([e child:@"id"].textAsDouble, 2.5, 0.01, nil);
}
Expand All @@ -64,11 +64,11 @@ - (void)testIntAttributes {

[rxml iterate:@"*" with:^(RXMLElement *e) {
if (i == 0) {
STAssertEquals([e attributeAsInt:@"id"], 1, nil);
STAssertEquals([e attributeAsInteger:@"id"], 1, nil);
} else if (i == 1) {
STAssertEqualsWithAccuracy([e attributeAsDouble:@"id"], 2.5, 0.01, nil);
} else if (i == 2) {
STAssertEquals([e attributeAsInt:@"id"], 3, nil);
STAssertEquals([e attributeAsInteger:@"id"], 3, nil);
}

i++;
Expand Down

0 comments on commit 90e188f

Please sign in to comment.