From: Adam M. <ama...@us...> - 2005-04-08 22:54:57
|
Update of /cvsroot/bibdesk/bibdesk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27573 Modified Files: BibAppController.m Log Message: Fix some parsing issues which caused the service to fail if spaces were present in the key or value (bug #854414). Title-only searches should also work better now; previously it scanned up to the first whitespace, but now we take the whole string. Index: BibAppController.m =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/BibAppController.m,v retrieving revision 1.99 retrieving revision 1.100 diff -C2 -d -r1.99 -r1.100 *** BibAppController.m 8 Apr 2005 15:27:27 -0000 1.99 --- BibAppController.m 8 Apr 2005 22:54:47 -0000 1.100 *************** *** 847,855 **** NSScanner *scanner; NSMutableDictionary *searchConstraints = [NSMutableDictionary dictionary]; ! NSString *queryString; ! NSMutableString *queryKey; NSCharacterSet *delimiterSet = [NSCharacterSet characterSetWithCharactersInString:@":="]; NSCharacterSet *ampersandSet = [NSCharacterSet characterSetWithCharactersInString:@"&"]; scanner = [NSScanner scannerWithString:string]; --- 847,861 ---- NSScanner *scanner; NSMutableDictionary *searchConstraints = [NSMutableDictionary dictionary]; ! NSString *queryString = nil; ! NSString *queryKey = nil; NSCharacterSet *delimiterSet = [NSCharacterSet characterSetWithCharactersInString:@":="]; NSCharacterSet *ampersandSet = [NSCharacterSet characterSetWithCharactersInString:@"&"]; + if([string rangeOfCharacterFromSet:delimiterSet].location == NSNotFound){ + [searchConstraints setObject:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] forKey:BDSKTitleString]; + return searchConstraints; + } + + scanner = [NSScanner scannerWithString:string]; *************** *** 857,886 **** // (we'll use a bunch of handy delimiters, including the first space, so it's flexible.) // alternatively we can just type the title, like we used to. ! ! [scanner scanCharactersFromSet:[NSCharacterSet alphanumericCharacterSet] intoString:&queryKey]; ! // scan the first key (also might be a simple title for original style search) ! ! if (![scanner isAtEnd]){ ! while(![scanner isAtEnd]){ ! [scanner scanCharactersFromSet:delimiterSet intoString:nil]; // scan the delimiters away ! [scanner scanUpToCharactersFromSet:ampersandSet intoString:&queryString]; // scan to either the end, or the next query key. ! // might have to remove a trailing space: ! if([[queryString substringWithRange:NSMakeRange([queryString length]-1,1)] isEqualToString:@" "]){ ! queryString = [queryString substringWithRange:NSMakeRange(0,[queryString length]-1)]; ! } ! [scanner scanCharactersFromSet:ampersandSet intoString:nil]; // scan the ampersands away. ! if(queryKey) ! [searchConstraints setObject:queryString forKey:[queryKey capitalizedString]]; ! if(![scanner isAtEnd]) // do i have to do this? ! [scanner scanCharactersFromSet:[NSCharacterSet alphanumericCharacterSet] intoString:&queryKey];// scan another ! } ! ! }else{ ! // if it was at end, we are done, and we'll scan in the title: ! if(queryKey){ ! [searchConstraints setObject:queryKey forKey:BDSKTitleString]; ! } else { ! searchConstraints = nil; ! } } --- 863,883 ---- // (we'll use a bunch of handy delimiters, including the first space, so it's flexible.) // alternatively we can just type the title, like we used to. ! [scanner setCharactersToBeSkipped:nil]; ! ! while(![scanner isAtEnd]){ ! // set these to nil explicitly, since we check for that later ! queryKey = nil; ! queryString = nil; ! [scanner scanUpToCharactersFromSet:delimiterSet intoString:&queryKey]; ! [scanner scanCharactersFromSet:delimiterSet intoString:nil]; // scan the delimiters away ! [scanner scanUpToCharactersFromSet:ampersandSet intoString:&queryString]; // scan to either the end, or the next query key. ! [scanner scanCharactersFromSet:ampersandSet intoString:nil]; // scan the ampersands away. ! ! // lose the whitespace, if any ! queryString = [queryString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; ! queryKey = [queryKey stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; ! ! if(queryKey && queryString) // make sure we have both a key and a value ! [searchConstraints setObject:queryString forKey:[queryKey capitalizedString]]; // BibItem field names are capitalized } |