Revision: 17976
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=17976&view=rev
Author: hofman
Date: 2011-06-27 16:58:21 +0000 (Mon, 27 Jun 2011)
Log Message:
-----------
simplify some code, fix range for possible bibtex strings
Modified Paths:
--------------
trunk/bibdesk/BDSKBibTeXWebParser.m
Modified: trunk/bibdesk/BDSKBibTeXWebParser.m
===================================================================
--- trunk/bibdesk/BDSKBibTeXWebParser.m 2011-06-27 11:11:51 UTC (rev 17975)
+++ trunk/bibdesk/BDSKBibTeXWebParser.m 2011-06-27 16:58:21 UTC (rev 17976)
@@ -61,39 +61,31 @@
+ (NSArray *)itemsFromDocument:(DOMDocument *)domDocument
xmlDocument:(NSXMLDocument *)xmlDocument fromURL:(NSURL *)url error:(NSError
**)outError{
// get a plain text representation of the document, erasing any XML
tags along the way
- NSString *document = [xmlDocument
XMLStringWithOptions:NSXMLDocumentTextKind];
+ NSString *inputString = [xmlDocument
XMLStringWithOptions:NSXMLDocumentTextKind];
AGRegex *cleanRegex = [AGRegex regexWithPattern:@"<[^>]*>"];
- document = [cleanRegex replaceWithString:@"" inString:document];
+ inputString = [cleanRegex replaceWithString:@"" inString:inputString];
- NSMutableArray *items = [NSMutableArray arrayWithCapacity:0];
+ NSMutableArray *items = [NSMutableArray array];
// get a list of all things that might be the beginnings of a BibTeX
item
AGRegex *regex = [AGRegex regexWithPattern:@"@[[:alpha:]]+[ \\t]*[{(]"];
- NSArray *sourceItems = [regex findAllInString:document];
-
- NSUInteger i;
- for (i = 0; i < [sourceItems count]; i++) {
+ NSArray *sourceItems = [regex findAllInString:inputString];
+ NSUInteger i, iMax = [sourceItems count];
+
+ for (i = 0; i < iMax; i++) {
AGRegexMatch *match = [sourceItems objectAtIndex:i];
NSString *sourceItem;
NSRange r = [match range];
- if (i < [sourceItems count] - 1) {
+ if (i < iMax - 1)
// if this isn't the last item, then we need to trim
the next item off of it
// since the BibTeX parser will parse as many
consecutive BibTeX strings as it can find
- NSRange r2 = [[sourceItems objectAtIndex:i+1] range];
- NSRange r3;
- r3.location = r.location;
- r3.length = r2.location - r.location + 1;
- sourceItem = [document substringWithRange:r3];
- } else {
- sourceItem = [document substringFromIndex:r.location];
- }
+ r.length = [[sourceItems objectAtIndex:i+1]
range].location - r.location;
+ else
+ r.length = [inputString length] - r.location;
+ sourceItem = [inputString substringWithRange:r];
// parse this string as BibTeX, if we can
- if ([BDSKBibTeXParser canParseString:sourceItem]) {
- NSArray *parsedItems = [BDSKBibTeXParser
itemsFromString:sourceItem owner:nil isPartialData:NO error:outError];
- if (parsedItems) {
- [items addObjectsFromArray:parsedItems];
- }
- }
+ if ([BDSKBibTeXParser canParseString:sourceItem])
+ [items addObjectsFromArray:[BDSKBibTeXParser
itemsFromString:sourceItem owner:nil isPartialData:NO error:outError]];
}
return items;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit