Permalink
Browse files

Clean up methods returning arrays

There's no real need to handle the case of 0 elements (from the xpath
query) separately. The fast enumeration will just not fill anything in.

The languages method is corrected to return an NSArray.

The tests still run OK.
  • Loading branch information...
1 parent 671f935 commit e51ecd706be3472155733fd92e50feb1f2db6295 @chrisridd committed Apr 6, 2012
Showing with 3 additions and 27 deletions.
  1. +1 −1 JTPepub/JTPepub.h
  2. +2 −26 JTPepub/JTPepub.m
View
@@ -61,6 +61,6 @@ typedef enum {
- (NSString *)isbn;
- (NSString *)drm;
- (NSDate *)expiryDate;
-- (NSMutableArray *)language;
+- (NSArray *)language;
@end
View
@@ -300,11 +300,6 @@ - (NSArray *)creatorsWithOPFRole:(NSString *)role
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:creator>s found
- return [NSArray array];
- }
NSMutableArray *results = [NSMutableArray array];
// Fast enumerate over meta elements
for(id item in metaElements)
@@ -340,11 +335,6 @@ - (NSArray *)contributorsWithOPFRole:(NSString *)role
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:contributor>s found
- return [NSArray array];
- }
NSMutableArray *results = [NSMutableArray array];
// Fast enumerate over meta elements
for (id item in metaElements)
@@ -570,11 +560,6 @@ - (NSDate *)publicationDate
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:date>s found
- return nil;
- }
// Find the date of publication.
// Fast enumerate over meta elements
for(id item in metaElements)
@@ -705,6 +690,7 @@ - (NSDate *)expiryDate
(void)[self drm];
return expiryDate;
}
+
/*
* Return an array of RFC5646 languange identifiers.
*/
@@ -714,20 +700,14 @@ - (NSArray *)language
return language;
}
- language = [[NSMutableArray alloc] initWithCapacity:1];
+ language = [[NSMutableArray alloc] init];
NSError *xmlError = nil;
NSArray *metaElements = [opfXML nodesForXPath:@"//dc:language"
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- // No <dc:language>s found - we should never get here in a valid epub!
- return language;
- }
-
// Enumerate over the elements we found.
for(id item in metaElements)
{
@@ -744,10 +724,6 @@ - (NSArray *)language
namespaces:xmlns
error:&xmlError];
- // Check the array isn't empty.
- if ([metaElements count] == 0) {
- return language;
- }
// Enumerate over the elements we found.
for(id item in metaElements)
{

0 comments on commit e51ecd7

Please sign in to comment.