Revision: 29634
http://sourceforge.net/p/bibdesk/svn/29634
Author: hofman
Date: 2025-09-27 16:27:02 +0000 (Sat, 27 Sep 2025)
Log Message:
-----------
return objc objects from functions
Modified Paths:
--------------
trunk/bibdesk/BDSKBibTeXParser.m
Modified: trunk/bibdesk/BDSKBibTeXParser.m
===================================================================
--- trunk/bibdesk/BDSKBibTeXParser.m 2025-09-26 17:07:27 UTC (rev 29633)
+++ trunk/bibdesk/BDSKBibTeXParser.m 2025-09-27 16:27:02 UTC (rev 29634)
@@ -491,8 +491,7 @@
return ([macros count] ? macros : nil);
}
-static CFArrayRef
-__BDCreateArrayOfNames(CFStringRef namesString)
+static NSArray *__BDSKArrayOfNames(CFStringRef namesString)
{
CFAllocatorRef allocator = CFAllocatorGetDefault();
CFIndex length = CFStringGetLength(namesString);
@@ -499,7 +498,7 @@
CFArrayRef separatorRanges = CFStringCreateArrayWithFindResults(allocator,
namesString, CFSTR(" and "), CFRangeMake(0, length), kCFCompareCaseInsensitive);
if(separatorRanges == NULL)
- return CFArrayCreate(allocator, (const void**)&namesString, 1, &
kCFTypeArrayCallBacks);
+ return [NSArray arrayWithObject:(__bridge NSString *)namesString];
CFIndex i, iMax = CFArrayGetCount(separatorRanges);
CFStringInlineBuffer inlineBuffer;
@@ -509,7 +508,7 @@
CFIndex startIndex = 0, currentIndex = 0, currentLength;
CFRange currentRange;
- CFMutableArrayRef array = CFArrayCreateMutable(allocator, iMax + 1,
&kCFTypeArrayCallBacks);
+ NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:iMax + 1];
for(i = 0; i < iMax + 1; i++){
if (i == iMax)
@@ -533,7 +532,7 @@
if(braceDepth == 0){
// braces balanced, so append the last name we found and reset the
startIndex
name = CFStringCreateWithSubstring(allocator, namesString,
CFRangeMake(startIndex, currentRange.location - startIndex));
- CFArrayAppendValue(array, name);
+ [array addObject:(__bridge NSString *)name];
CFRelease(name);
startIndex = currentIndex;
}
@@ -543,8 +542,7 @@
// returning NULL will signify our error condition
if(braceDepth != 0){
- CFRelease(array);
- array = NULL;
+ array = nil;
}
return array;
@@ -559,7 +557,7 @@
// This is equivalent to btparse's bt_split_list(str, "and", "BibTex
Name", 0, ""), but avoids UTF8String conversion
// check brace depth; corporate authors such as {Someone and Someone Else,
Inc} use braces, so this parsing is BibTeX-specific, rather than general string
handling
- CFArrayRef names = __BDCreateArrayOfNames((__bridge CFStringRef)aString);
+ NSArray *names = __BDSKArrayOfNames((__bridge CFStringRef)aString);
// shouldn't ever see this case as far as I know, as long as we're using
btparse
if(names == NULL){
@@ -571,10 +569,7 @@
return authors;
}
- CFIndex i = 0, iMax = CFArrayGetCount(names);
-
- for(i = 0; i < iMax; i++){
- NSString *name = (__bridge NSString *)CFArrayGetValueAtIndex(names, i);
+ for(NSString *name in names){
BibAuthor *theAuthor = nil;
for (BibAuthor *anAuthor in oldAuthors) {
if ([[anAuthor originalName] isEqualToString:name]) {
@@ -586,12 +581,11 @@
theAuthor = [[BibAuthor alloc] initWithName:name publication:pub
forField:field];
[authors addObject:theAuthor];
}
- CFRelease(names);
return authors;
}
// creates an NSString from the given bt_name and bt_namepart, which were
parsed with the given encoding; returns nil if no such name component exists
-static CFStringRef __BDCreateNameStringForComponent(CFAllocatorRef alloc,
bt_name *theName, bt_namepart thePart, CFStringEncoding encoding)
+static NSString *__BDSKNameStringForComponent(CFAllocatorRef alloc, bt_name
*theName, bt_namepart thePart, CFStringEncoding encoding)
{
NSInteger i, numberOfTokens = theName->part_len[thePart];
CFStringRef theString = NULL;
@@ -613,7 +607,7 @@
}
theString = mutableString;
}
- return theString;
+ return CFBridgingRelease(theString);
}
+ (NSDictionary *)nameComponents:(NSString *)aName forPublication:(BibItem
*)pub{
@@ -682,22 +676,22 @@
if(shouldFree)
CFAllocatorDeallocate(alloc, (void *)name_cstring);
- CFStringRef nameString = NULL;
+ NSString *nameString = nil;
- if ((nameString = __BDCreateNameStringForComponent(alloc, theName,
BTN_FIRST, encoding))) {
- [parts setObject:CFBridgingRelease(nameString) forKey:@"first"];
+ if ((nameString = __BDSKNameStringForComponent(alloc, theName, BTN_FIRST,
encoding))) {
+ [parts setObject:nameString forKey:@"first"];
}
- if ((nameString = __BDCreateNameStringForComponent(alloc, theName,
BTN_VON, encoding))) {
- [parts setObject:CFBridgingRelease(nameString) forKey:@"von"];
+ if ((nameString = __BDSKNameStringForComponent(alloc, theName, BTN_VON,
encoding))) {
+ [parts setObject:nameString forKey:@"von"];
}
- if ((nameString = __BDCreateNameStringForComponent(alloc, theName,
BTN_LAST, encoding))) {
- [parts setObject:CFBridgingRelease(nameString) forKey:@"last"];
+ if ((nameString = __BDSKNameStringForComponent(alloc, theName, BTN_LAST,
encoding))) {
+ [parts setObject:nameString forKey:@"last"];
}
- if ((nameString = __BDCreateNameStringForComponent(alloc, theName, BTN_JR,
encoding))) {
- [parts setObject:CFBridgingRelease(nameString) forKey:@"jr"];
+ if ((nameString = __BDSKNameStringForComponent(alloc, theName, BTN_JR,
encoding))) {
+ [parts setObject:nameString forKey:@"jr"];
}
bt_free_name(theName);
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