Revision: 27774
http://sourceforge.net/p/bibdesk/svn/27774
Author: hofman
Date: 2022-07-28 09:44:23 +0000 (Thu, 28 Jul 2022)
Log Message:
-----------
try parsed format without unique characters first before running loop
Modified Paths:
--------------
trunk/bibdesk/BDSKFormatParser.m
Modified: trunk/bibdesk/BDSKFormatParser.m
===================================================================
--- trunk/bibdesk/BDSKFormatParser.m 2022-07-27 21:33:35 UTC (rev 27773)
+++ trunk/bibdesk/BDSKFormatParser.m 2022-07-28 09:44:23 UTC (rev 27774)
@@ -854,17 +854,21 @@
char fallback[number + 1];
memset(fallback, '\0', number + 1);
- if (number > 0) {
- if (hash != NSNotFound) {
- // first try unique characters based on the hashed field, to get a
deterministic value
- // consistent with the universal cite key of Papers 2 and 3
- for (n = number; n > 0; n--, hash /= charRange.length)
- fallback[n - 1] = charRange.location + (hash %
charRange.length);
- if ((uniqueStr = validator([NSString stringWithFormat:@"%@%s%@",
baseStr, fallback, endStr])))
- return uniqueStr;
- } else {
- memset(fallback, NSMaxRange(charRange) - 1, number);
- }
+ if (number == 0) {
+ // first try without unique characters and prefix/suffix
+ if ((uniqueStr = validator([baseStr stringByAppendingString:endStr])))
+ return uniqueStr;
+ if (prefix) baseStr = [baseStr stringByAppendingString:prefix];
+ if (suffix) endStr = [suffix stringByAppendingString:endStr];
+ } else if (hash != NSNotFound) {
+ // first try unique characters based on the hashed field, to get a
deterministic value
+ // consistent with the universal cite key of Papers 2 and 3
+ for (n = number; n > 0; n--, hash /= charRange.length)
+ fallback[n - 1] = charRange.location + (hash % charRange.length);
+ if ((uniqueStr = validator([NSString stringWithFormat:@"%@%s%@",
baseStr, fallback, endStr])))
+ return uniqueStr;
+ } else {
+ memset(fallback, NSMaxRange(charRange) - 1, number);
}
__block NSString *(^uniqueString)(char *, NSUInteger, NSUInteger) =
^NSString *(char *chars, NSUInteger count, NSUInteger i) {
@@ -878,20 +882,12 @@
}
return nil;
} else {
- NSMutableString *str = [NSMutableString stringWithString:baseStr];
- if (count) {
- if (prefix) [str appendString:prefix];
- [str appendFormat:@"%s", chars];
- if (suffix) [str appendString:suffix];
- }
- [str appendString:endStr];
- // validate the result
- return validator(str);
+ return validator([NSString stringWithFormat:@"%@%s%@", baseStr,
chars, endStr]);
}
};
// run along characters to find one that is unique
- n = number;
+ n = MAX(number, 1);
do {
char chars[n + 1];
memset(chars, '\0', n + 1);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit