Hello,
I've factored out my DOI parsing into an NSString category. I wondered
1) if this looks ok (I know it works)
http://pastie.org/361295 or see below
2) where the best place to put it is. Right now it's in
BibItem_PubMedLookup
3) is it worthwhile/possible trying to make the regexes static if it gets
used a lot?
Many thanks,
Greg.
@implementation NSString (PubMedLookup)
- (NSString *) stringByExtractingDOIFromString;
{
NSString *doi=nil;
AGRegex *doiRegex = [AGRegex regexWithPattern:@"doi[: ]+([0-9.]+[
\\/][A-Z0-9.\\-_]+)"
options:AGRegexMultiline|AGRegexCaseInsensitive];
AGRegexMatch *match = [doiRegex findInString:self];
if([match groupAtIndex:1]!=nil){
doi = [NSString stringWithString:[match groupAtIndex:1]];
// replace any spaces with /
// first converting any internal whitespace to single space
doi = [doi stringByNormalizingSpacesAndLineBreaks];
doi = [doi stringByReplacingOccurrencesOfString:@" "
withString:@"/"];
} else {
// Be more restrictive about initial part but less about
// actual DOI string - offer 3 alternatives for 'hinge'
// including standard slash
AGRegex *doiRegex2 = [AGRegex regexWithPattern:@"doi[:
]+(10\\.[0-9]{4})[ \\/0]([A-Z0-9.\\-_]+)"
options:AGRegexMultiline|AGRegexCaseInsensitive];
match = [doiRegex2 findInString:self];
if([match groupAtIndex:1]!=nil && [match groupAtIndex:2]!=nil)
doi = [NSString stringWithFormat:@"%@/%@",[match
groupAtIndex:1],[match groupAtIndex:2]];
}
return doi;
}
@end
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Bibdesk-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-develop