Skip to content
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

Misc changes & method rename suggestion #56

Open
wants to merge 5 commits 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
4 changes: 2 additions & 2 deletions AttributeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ - (void)testAttributedText {
STAssertEquals(atts.count, 2U, nil);
STAssertTrue([atts containsObject:@"count"], nil);
STAssertTrue([atts containsObject:@"style"], nil);

RXMLElement *squarexml = [rxml child:@"square"];
RXMLElement *squarexml = [rxml childElementWithTag:@"square"];
atts = [squarexml attributeNames];
STAssertEquals(atts.count, 3U, nil);
STAssertTrue([atts containsObject:@"name"], nil);
Expand Down
23 changes: 16 additions & 7 deletions RaptureXML.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
02ADE6A916A0E491008643D5 /* EncodingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02F3A4041526D7BC00E8C822 /* EncodingTests.m */; };
02ADE6AA16A0E491008643D5 /* XPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 027B6BCF153C652E00A4EDF2 /* XPathTests.m */; };
02F3A3FF1526D22600E8C822 /* players.xml in Resources */ = {isa = PBXBuildFile; fileRef = 0DEB8F2D14681BD800024989 /* players.xml */; };
0C407E54187AD99100050661 /* RXMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 027DAC2E14FBF443001BA563 /* RXMLElement.h */; settings = {ATTRIBUTES = (Public, ); }; };
0DEB8EB51467EC9B00024989 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B2C5142ADFC60018B75D /* Foundation.framework */; };
0DEB8F2C14681A9400024989 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0252B305142AE3FF0018B75D /* libz.dylib */; };
5415BE4216FC638100AFC566 /* HTMLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5415BE4116FC638100AFC566 /* HTMLTests.m */; };
Expand Down Expand Up @@ -208,6 +209,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
0C407E54187AD99100050661 /* RXMLElement.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -255,7 +257,7 @@
0252B2B6142ADFC60018B75D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0500;
ORGANIZATIONNAME = "Rapture In Venice";
};
buildConfigurationList = 0252B2B9142ADFC60018B75D /* Build configuration list for PBXProject "RaptureXML" */;
Expand Down Expand Up @@ -375,8 +377,9 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -391,11 +394,15 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -404,18 +411,22 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
Expand All @@ -437,8 +448,6 @@
GCC_VERSION = "";
HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_AFTER_BUILD = YES;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Debug;
Expand All @@ -456,8 +465,6 @@
GCC_VERSION = "";
HEADER_SEARCH_PATHS = "\"$(SDK_DIR)\"/usr/include/libxml2/**";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_AFTER_BUILD = YES;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Release;
Expand Down Expand Up @@ -489,6 +496,7 @@
"\"$(SRCROOT)/../WordsWithPractice/WordsWithPractice/GoogleAdMobAdsSDK\"",
);
PRODUCT_NAME = "$(TARGET_NAME)";
PUBLIC_HEADERS_FOLDER_PATH = "include/$(PRODUCT_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
Expand Down Expand Up @@ -520,6 +528,7 @@
"\"$(SRCROOT)/../WordsWithPractice/WordsWithPractice/GoogleAdMobAdsSDK\"",
);
PRODUCT_NAME = "$(TARGET_NAME)";
PUBLIC_HEADERS_FOLDER_PATH = "include/$(PRODUCT_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
Expand Down
20 changes: 9 additions & 11 deletions RaptureXML/RXMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
//

#import <Foundation/Foundation.h>
#import <libxml2/libxml/xmlreader.h>
#import <libxml2/libxml/xmlmemory.h>
#import <libxml2/libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>

typedef struct _xmlDoc *xmlDocPtr;/* frorward declaration */
typedef struct _xmlNode *xmlNodePtr; /* frorward declaration */

@interface RXMLDocHolder : NSObject {
xmlDocPtr doc_;
Expand Down Expand Up @@ -87,14 +85,14 @@
- (double)attributeAsDouble:(NSString *)attributeName;
- (double)attributeAsDouble:(NSString *)attributeName inNamespace:(NSString *)ns;

- (RXMLElement *)child:(NSString *)tag;
- (RXMLElement *)child:(NSString *)tag inNamespace:(NSString *)ns;
- (RXMLElement *)childElementWithTag:(NSString *)tag;
- (RXMLElement *)childElementWithTag:(NSString *)tag inNamespace:(NSString *)ns;

- (NSArray *)children:(NSString *)tag;
- (NSArray *)children:(NSString *)tag inNamespace:(NSString *)ns;
- (NSArray *)childrenWithRootXPath:(NSString *)xpath;
- (NSArray *)childrenArrayWithTag:(NSString *)tag;
- (NSArray *)childrenArrayWithTag:(NSString *)tag inNamespace:(NSString *)ns;
- (NSArray *)childrenArrayWithRootXPath:(NSString *)xpath;

- (void)iterate:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk;
- (void)iterateWithQuery:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk;
- (void)iterateWithRootXPath:(NSString *)xpath usingBlock:(void (^)(RXMLElement *))blk;
- (void)iterateElements:(NSArray *)elements usingBlock:(void (^)(RXMLElement *))blk;

Expand Down
39 changes: 16 additions & 23 deletions RaptureXML/RXMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
//

#import "RXMLElement.h"
#import <libxml2/libxml/xmlreader.h>
#import <libxml2/libxml/xmlmemory.h>
#import <libxml2/libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>

@implementation RXMLDocHolder

Expand Down Expand Up @@ -267,11 +272,7 @@ - (NSString *)attribute:(NSString *)attName {
- (NSString *)attribute:(NSString *)attName inNamespace:(NSString *)ns {
const unsigned char *attCStr = xmlGetNsProp(node_, (const xmlChar *)[attName cStringUsingEncoding:NSUTF8StringEncoding], (const xmlChar *)[ns cStringUsingEncoding:NSUTF8StringEncoding]);

if (attCStr) {
return [NSString stringWithUTF8String:(const char *)attCStr];
}

return nil;
return attCStr ? [NSString stringWithUTF8String:(const char *)attCStr] : nil;
}

- (NSArray *)attributeNames {
Expand Down Expand Up @@ -306,7 +307,7 @@ - (BOOL)isValid {

#pragma mark -

- (RXMLElement *)child:(NSString *)tag {
- (RXMLElement *)childElementWithTag:(NSString *)tag {
NSArray *components = [tag componentsSeparatedByString:@"."];
xmlNodePtr cur = node_;

Expand Down Expand Up @@ -336,14 +337,10 @@ - (RXMLElement *)child:(NSString *)tag {
}
}

if (cur) {
return [RXMLElement elementFromXMLDoc:self.xmlDoc node:cur];
}

return nil;
return cur ? [RXMLElement elementFromXMLDoc:self.xmlDoc node:cur] : nil;
}

- (RXMLElement *)child:(NSString *)tag inNamespace:(NSString *)ns {
- (RXMLElement *)childElementWithTag:(NSString *)tag inNamespace:(NSString *)ns {
NSArray *components = [tag componentsSeparatedByString:@"."];
xmlNodePtr cur = node_;
const xmlChar *namespaceC = (const xmlChar *)[ns cStringUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -374,14 +371,10 @@ - (RXMLElement *)child:(NSString *)tag inNamespace:(NSString *)ns {
}
}

if (cur) {
return [RXMLElement elementFromXMLDoc:self.xmlDoc node:cur];
}

return nil;
return cur ? [RXMLElement elementFromXMLDoc:self.xmlDoc node:cur] : nil;
}

- (NSArray *)children:(NSString *)tag {
- (NSArray *)childrenArrayWithTag:(NSString *)tag {
const xmlChar *tagC = (const xmlChar *)[tag cStringUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *children = [NSMutableArray array];
xmlNodePtr cur = node_->children;
Expand All @@ -397,7 +390,7 @@ - (NSArray *)children:(NSString *)tag {
return [children copy];
}

- (NSArray *)children:(NSString *)tag inNamespace:(NSString *)ns {
- (NSArray *)childrenArrayWithTag:(NSString *)tag inNamespace:(NSString *)ns {
const xmlChar *tagC = (const xmlChar *)[tag cStringUsingEncoding:NSUTF8StringEncoding];
const xmlChar *namespaceC = (const xmlChar *)[ns cStringUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *children = [NSMutableArray array];
Expand All @@ -414,7 +407,7 @@ - (NSArray *)children:(NSString *)tag inNamespace:(NSString *)ns {
return [children copy];
}

- (NSArray *)childrenWithRootXPath:(NSString *)xpath {
- (NSArray *)childrenArrayWithRootXPath:(NSString *)xpath {
// check for a query
if (!xpath) {
return [NSArray array];
Expand Down Expand Up @@ -454,7 +447,7 @@ - (NSArray *)childrenWithRootXPath:(NSString *)xpath {

#pragma mark -

- (void)iterate:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk {
- (void)iterateWithQuery:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk {
// check for a query
if (!query) {
return;
Expand All @@ -477,7 +470,7 @@ - (void)iterate:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk {
if (cur->type == XML_ELEMENT_NODE) {
RXMLElement *element = [RXMLElement elementFromXMLDoc:self.xmlDoc node:cur];
NSString *restOfQuery = [[components subarrayWithRange:NSMakeRange(i + 1, components.count - i - 1)] componentsJoinedByString:@"."];
[element iterate:restOfQuery usingBlock:blk];
[element iterateWithQuery:restOfQuery usingBlock:blk];
}

cur = cur->next;
Expand Down Expand Up @@ -528,7 +521,7 @@ - (void)iterate:(NSString *)query usingBlock:(void (^)(RXMLElement *))blk {
}

- (void)iterateWithRootXPath:(NSString *)xpath usingBlock:(void (^)(RXMLElement *))blk {
NSArray *children = [self childrenWithRootXPath:xpath];
NSArray *children = [self childrenArrayWithRootXPath:xpath];
[self iterateElements:children usingBlock:blk];
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/BoundaryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)testEmptyTopTagXML {
RXMLElement *rxml = [RXMLElement elementFromXMLString:emptyTopTagXML_ encoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEqualObjects(rxml.text, @"", nil);
STAssertEqualObjects([rxml childrenWithRootXPath:@"*"], [NSArray array], nil);
STAssertEqualObjects([rxml childrenArrayWithRootXPath:@"*"], [NSArray array], nil);
}

- (void)testAttribute {
Expand All @@ -60,26 +60,26 @@ - (void)testNamespaceAttribute {
- (void)testChild {
RXMLElement *rxml = [RXMLElement elementFromXMLString:childXML_ encoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEqualObjects([rxml child:@"empty_child"].text, @"", nil);
STAssertEqualObjects([rxml child:@"text_child"].text, @"foo", nil);
STAssertEqualObjects([rxml childElementWithTag:@"empty_child"].text, @"", nil);
STAssertEqualObjects([rxml childElementWithTag:@"text_child"].text, @"foo", nil);
}

- (void)testNamespaceChild {
RXMLElement *rxml = [RXMLElement elementFromXMLString:namespaceXML_ encoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEqualObjects([rxml child:@"text" inNamespace:@"*"].text, @"something", nil);
STAssertEqualObjects([rxml childElementWithTag:@"text" inNamespace:@"*"].text, @"something", nil);
}

- (void)testChildren {
RXMLElement *rxml = [RXMLElement elementFromXMLString:childrenXML_ encoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEquals([rxml children:@"child"].count, 3U, nil);
STAssertEquals([rxml childrenArrayWithTag:@"child"].count, 3U, nil);
}

- (void)testNamespaceChildren {
RXMLElement *rxml = [RXMLElement elementFromXMLString:namespaceXML_ encoding:NSUTF8StringEncoding];
STAssertTrue(rxml.isValid, nil);
STAssertEquals([rxml children:@"text" inNamespace:@"*"].count, 1U, nil);
STAssertEquals([rxml childrenArrayWithTag:@"text" inNamespace:@"*"].count, 1U, nil);
}

@end
4 changes: 2 additions & 2 deletions Tests/CopyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (void)testTags {
RXMLElement *rxml2 = [rxml copy];
__block NSInteger i = 0;

[rxml2 iterate:@"*" usingBlock:^(RXMLElement *e) {
[rxml2 iterateWithQuery:@"*" usingBlock:^(RXMLElement *e) {
if (i == 0) {
STAssertEqualObjects(e.tag, @"square", nil);
STAssertEqualObjects(e.text, @"Square", nil);
Expand All @@ -78,7 +78,7 @@ - (void)testAttributes {
RXMLElement *rxml2 = [rxml copy];
__block NSInteger i = 0;

[rxml2 iterate:@"*" usingBlock:^(RXMLElement *e) {
[rxml2 iterateWithQuery:@"*" usingBlock:^(RXMLElement *e) {
if (i == 0) {
STAssertEqualObjects([e attribute:@"name"], @"Square", nil);
} else if (i == 1) {
Expand Down
8 changes: 4 additions & 4 deletions Tests/DeepChildrenTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ - (void)testQuery {
__block NSInteger i = 0;

// count the players
RXMLElement *players = [rxml child:@"players"];
NSArray *children = [players children:@"player"];
RXMLElement *players = [rxml childElementWithTag:@"players"];
NSArray *children = [players childrenArrayWithTag:@"player"];

[rxml iterateElements:children usingBlock: ^(RXMLElement *e) {
i++;
Expand All @@ -36,7 +36,7 @@ - (void)testDeepChildQuery {
RXMLElement *rxml = [RXMLElement elementFromXMLFile:@"players.xml"];

// count the players
RXMLElement *coachingYears = [rxml child:@"players.coach.experience.years"];
RXMLElement *coachingYears = [rxml childElementWithTag:@"players.coach.experience.years"];

STAssertEquals(coachingYears.textAsInt, 1, nil);
}
Expand All @@ -45,7 +45,7 @@ - (void)testDeepChildQueryWithWildcard {
RXMLElement *rxml = [RXMLElement elementFromXMLFile:@"players.xml"];

// count the players
RXMLElement *coachingYears = [rxml child:@"players.coach.experience.teams.*"];
RXMLElement *coachingYears = [rxml childElementWithTag:@"players.coach.experience.teams.*"];

// first team returned
STAssertEquals(coachingYears.textAsInt, 53, nil);
Expand Down
6 changes: 3 additions & 3 deletions Tests/DeepTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (void)testQuery {
// count the players
i = 0;

[rxml iterate:@"players.player" usingBlock: ^(RXMLElement *e) {
[rxml iterateWithQuery:@"players.player" usingBlock: ^(RXMLElement *e) {
i++;
}];

Expand All @@ -33,7 +33,7 @@ - (void)testQuery {
// count the first player's name
i = 0;

[rxml iterate:@"players.player.name" usingBlock: ^(RXMLElement *e) {
[rxml iterateWithQuery:@"players.player.name" usingBlock: ^(RXMLElement *e) {
i++;
}];

Expand All @@ -42,7 +42,7 @@ - (void)testQuery {
// count the coaches
i = 0;

[rxml iterate:@"players.coach" usingBlock: ^(RXMLElement *e) {
[rxml iterateWithQuery:@"players.coach" usingBlock: ^(RXMLElement *e) {
i++;
}];

Expand Down
Loading