[futurebasic] Re: [FB] seeking suggestion, removing multiple extensions

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2013 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Thu, 6 Jun 2013 00:22:06 +0100
Wave wrote:

> I'm hoping someone has an idea they would mind sharing about my current problem.
> I'm removing all the extensions from a URL and what I have works, however I can't seem to figure out the logic to release all the URLs elegantly, except for the first one (index 0 ) and the last, which holds the final URL.
> My max array is arbitrarily set to 5 because I don't think that I would encounter more than five extension but that's actually bad validation
> The first and the last are released by the caller.

A very quick look.
include "ConsoleWindow"

local fn CFURLCopyCleaningAllExtensions( inURL as CFURLRef ) as CFURLRef
dim as CFStringRef   exten
dim as CFURLRef      outURL, tempURL

outURL = fn CFURLCreateCopyDeletingPathExtension( _kCFAllocatorDefault, inURL )
exten = fn CFURLCopyPathExtension( outURL )
while ( exten )
CFRelease( exten )
tempURL = fn CFURLCreateCopyDeletingPathExtension( _kCFAllocatorDefault, outURL )
CFRelease( outURL )
outURL = tempURL 
exten = fn CFURLCopyPathExtension( outURL )
end fn = outURL

local fn TestCleaner
dim as CFURLRef    notRealPathURL, finalURL
dim as CFStringRef testPathStr

testPathStr = @"/Users/wedwards/Desktop/Speech/NotRealFolder.app/fileWithMultipleExtensions.jpg.txt.xml.zip"
notRealPathURL = fn CFURLCreateWithString( _kCFAllocatorDefault, testPathStr, NULL )
finalURL = fn CFURLCopyCleaningAllExtensions( notRealPathURL )
CFRelease( notRealPathURL )

print "Before:"
fn ConsolePrintCFType( testPathStr )

print "After:"
fn ConsolePrintCFType( finalURL )

CFRelease( finalURL )
end fn

fn TestCleaner