Revision: 22522
http://sourceforge.net/p/bibdesk/svn/22522
Author: hofman
Date: 2018-08-24 09:37:32 +0000 (Fri, 24 Aug 2018)
Log Message:
-----------
reuse local variables
Modified Paths:
--------------
trunk/bibdesk/BDSKHCiteParser.m
Modified: trunk/bibdesk/BDSKHCiteParser.m
===================================================================
--- trunk/bibdesk/BDSKHCiteParser.m 2018-08-24 09:26:45 UTC (rev 22521)
+++ trunk/bibdesk/BDSKHCiteParser.m 2018-08-24 09:37:32 UTC (rev 22522)
@@ -105,12 +105,15 @@
- (NSMutableDictionary *)dictionaryFromCitationNode:(DOMNode *)citationNode
isContainer:(BOOL)isContainer xpaths:(NSDictionary *)xpaths{
BDSKTypeManager *typeMan = [BDSKTypeManager sharedManager];
NSMutableDictionary *rd = [NSMutableDictionary dictionaryWithCapacity:0];
+ NSArray *nodes;
+ DOMNode *node;
+ NSMutableArray *array;
// find type but not type that's a descendant of 'container'.
- NSArray *typeNodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"type"]];
+ nodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"type"]];
NSString *typeString = nil;
- for (DOMNode *node in typeNodes) {
+ for (node in nodes) {
if(isContainer || [self nodeHasContainerParent:node] == NO)
typeString = [self fullStringValueIfABBRFromNode:node];
}
@@ -124,9 +127,9 @@
// find title node
- NSArray *titleNodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"title"]];
+ nodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"title"]];
- for(DOMNode *node in titleNodes){
+ for(node in nodes){
// deal with this citation's container later
// note: todo - avoid second hasParentWithClassName by finding
container
// nodes first and caching those then checking against them here. (if
necessary)
@@ -136,37 +139,34 @@
// find authors
- NSString *authorXpath = @".//*[contains(concat('
',normalize-space(@class), ' '),' creator ') and contains(concat('
',normalize-space(@class), ' '),' vcard ')]";
- NSArray *authorNodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"author"]];
- NSMutableString *BTAuthString = [NSMutableString stringWithCapacity:0];
+ nodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"author"]];
+ array = [NSMutableArray array];
- for(DOMNode *node in authorNodes){
- if ([BTAuthString length]) [BTAuthString appendFormat:@" and "];
- [BTAuthString appendString:[self BTAuthorStringFromVCardNode:node
xpath:[xpaths objectForKey:@"fn"]]];
- }
- [rd setObject:BTAuthString forKey:BDSKAuthorString];
+ for(node in nodes)
+ [array addObject:[self BTAuthorStringFromVCardNode:node xpath:[xpaths
objectForKey:@"fn"]]];
+ [rd setObject:[array componentsJoinedByString:@" and "]
forKey:BDSKAuthorString];
// find keywords
- NSArray *tagNodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"tag"]];
+ nodes = [citationNode nodesForXPathExpression:[xpaths
objectForKey:@"tag"]];
- [rd setObject:[[tagNodes valueForKey:@"stringValue"]
componentsJoinedByString:@"; "] forKey:BDSKKeywordsString];
+ [rd setObject:[[nodes valueForKey:@"stringValue"]
componentsJoinedByString:@"; "] forKey:BDSKKeywordsString];
// find description (append multiple descriptions to avoid data loss)
- NSMutableArray *descNodes = [NSMutableArray arrayWithCapacity:0];
- [descNodes addObjectsFromArray:[citationNode
nodesForXPathExpression:[xpaths objectForKey:@"description"]]];
- [descNodes addObjectsFromArray:[citationNode
nodesForXPathExpression:[xpaths objectForKey:@"abstract"]]];
+ array = [NSMutableArray array];
+ [array addObjectsFromArray:[citationNode nodesForXPathExpression:[xpaths
objectForKey:@"description"]]];
+ [array addObjectsFromArray:[citationNode nodesForXPathExpression:[xpaths
objectForKey:@"abstract"]]];
- [rd setObject:[[descNodes valueForKey:@"stringValue"]
componentsJoinedByString:@"\n"] forKey:BDSKAbstractString];
+ [rd setObject:[[array valueForKey:@"stringValue"]
componentsJoinedByString:@"\n"] forKey:BDSKAbstractString];
// find date published
// Only use the first such node.
- DOMNode *datePublishedNode = [citationNode
singleNodeForXPathExpression:[xpaths objectForKey:@"date-published"]];
+ node = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"date-published"]];
- if(datePublishedNode) {
- NSDate *datePublished = [self dateFromNode:datePublishedNode];
+ if(node) {
+ NSDate *datePublished = [self dateFromNode:node];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setDateFormat:@"yyyy"];
@@ -179,32 +179,32 @@
// find issue
// Only use the first such node.
- DOMNode *issueNode = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"issue"]];
+ node = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"issue"]];
- if(issueNode) {
- [rd setObject:[issueNode stringValue] forKey:@"Issue"];
+ if(node) {
+ [rd setObject:[node stringValue] forKey:@"Issue"];
}
// find pages
// Only use the first such node.
- DOMNode *pagesNode = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"pages"]];
+ node = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"pages"]];
- if(pagesNode) {
- [rd setObject:[pagesNode stringValue] forKey:BDSKPagesString];
+ if(node) {
+ [rd setObject:[node stringValue] forKey:BDSKPagesString];
}
// find URI
- DOMNode *URINode = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"uri"]];
+ node = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"uri"]];
- if(URINode) {
+ if(node) {
NSString *URIString = nil;
- if([[URINode nodeName] isCaseInsensitiveEqual:@"a"]){
- URIString = [(DOMElement *)URINode getAttribute:@"href"];
+ if([[node nodeName] isCaseInsensitiveEqual:@"a"]){
+ URIString = [(DOMElement *)node getAttribute:@"href"];
}else{
- URIString = [self fullStringValueIfABBRFromNode:URINode];
+ URIString = [self fullStringValueIfABBRFromNode:node];
}
if([URIString hasCaseInsensitivePrefix:@"http://"] || [URIString
hasCaseInsensitivePrefix:@"https://"]){
@@ -211,7 +211,6 @@
[rd setObject:URIString forKey:BDSKUrlString];
} else {
[rd setObject:URIString forKey:@"Uri"];
-
}
}
@@ -218,12 +217,12 @@
// get container info:
// *** NOTE: should do this last, to avoid overwriting data
- DOMNode *containerNode = [citationNode
singleNodeForXPathExpression:[xpaths objectForKey:@"container"]];
+ node = [citationNode singleNodeForXPathExpression:[xpaths
objectForKey:@"container"]];
- if(containerNode) {
+ if(node) {
NSString *citationType = [rd objectForKey:BDSKTypeString];
- NSMutableDictionary *containerDict = [NSMutableDictionary
dictionaryWithDictionary:[self dictionaryFromCitationNode:containerNode
isContainer:YES xpaths:xpaths]];
+ NSMutableDictionary *containerDict = [NSMutableDictionary
dictionaryWithDictionary:[self dictionaryFromCitationNode:node isContainer:YES
xpaths:xpaths]];
NSString *containerTitle = [containerDict
objectForKey:BDSKTitleString];
NSString *containerType = [containerDict objectForKey:BDSKTypeString];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit