From 3366099dbe7c7c6a7db853a8e1ee5cf6b66fbbc0 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 24 Jun 2022 13:17:43 -0500 Subject: [PATCH] can you call C++ methods from Smalltalk --- extern/nfd-modified/src/nfd_cocoa.mm | 46 ++++++++++++---------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/extern/nfd-modified/src/nfd_cocoa.mm b/extern/nfd-modified/src/nfd_cocoa.mm index 2f08a3a24..5b5ee4cc0 100644 --- a/extern/nfd-modified/src/nfd_cocoa.mm +++ b/extern/nfd-modified/src/nfd_cocoa.mm @@ -22,32 +22,26 @@ static NSArray *BuildAllowedFileTypes( const std::vector& filterLis // NSMutableArray *buildFilterList = NSMutableArray::alloc()->init(); NSMutableArray *buildFilterList = [[NSMutableArray alloc] init]; - char typebuf[NFD_MAX_STRLEN] = {0}; - - size_t filterListLen = strlen(filterList); - char *p_typebuf = typebuf; - for ( size_t i = 0; i < filterListLen+1; ++i ) - { - if ( filterList[i] == ',' || filterList[i] == ';' || filterList[i] == '\0' ) - { - if (filterList[i] != '\0') - ++p_typebuf; - *p_typebuf = '\0'; - - // or this: NSString::stringWithUTF8String(typebuf); - // buildFilterList->addObject(thisType); - // really? did you have to make this mess?! - NSString *thisType = [NSString stringWithUTF8String: typebuf]; - [buildFilterList addObject:thisType]; - p_typebuf = typebuf; - *p_typebuf = '\0'; - } - else - { - *p_typebuf = filterList[i]; - ++p_typebuf; - + String typebuf; + for (std::string& i: filterList) { + typebuf=""; + for (char& j: i) { + if (j==' ' || j==',' || j ==';') { + // or this: NSString::stringWithUTF8String(typebuf); + // buildFilterList->addObject(thisType); + // really? did you have to make this mess?! + NSString *thisType = [NSString stringWithUTF8String: [typebuf c_str]]; + [buildFilterList addObject:thisType]; + typebuf=""; + } else if (j!='.' && j!='*') { + typebuf+=j; } + } + if (!typebuf.empty()) { + // I don't think this will work, but come on... + NSString *thisType = [NSString stringWithUTF8String: [typebuf c_str]]; + [buildFilterList addObject:thisType]; + } } NSArray *returnArray = [NSArray arrayWithArray:buildFilterList]; @@ -58,7 +52,7 @@ static NSArray *BuildAllowedFileTypes( const std::vector& filterLis static void AddFilterListToDialog( NSSavePanel *dialog, const std::vector& filterList ) { - if ( !filterList || strlen(filterList) == 0 ) + if ( filterList.size()&1 ) return; NSArray *allowedFileTypes = BuildAllowedFileTypes( filterList );