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

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

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Wed, 5 Jun 2013 18:41:42 -0500
Very quick look indeed.  That was fast, elegant and exactly what I needed.
I cant tell you how much time I spent trying to figure that function out.

Thanks Bernie,


W.

________________________________________
From: futurebasic@... [futurebasic@...] On Behalf Of Bernie [fblist.bw@...]
Sent: Wednesday, June 05, 2013 7:22 PM
To: futurebasic@...
Subject: Re: [FB] seeking suggestion, removing multiple extensions

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
'~'1
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 )
wend
end fn = outURL

local fn TestCleaner
'~'1
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
'---------------



--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...
To access the list archives, go to:  http://freegroups.net/groups/futurebasic/