Re: Conversion from an absolute URL to relative
Re: Conversion from an absolute URL to relative
- Subject: Re: Conversion from an absolute URL to relative
- From: Satoshi Matsumoto <email@hidden>
- Date: Wed, 10 Mar 2004 20:48:03 +0900
Hi, Louis
on 04.3.10 8:12 PM, Louis C. Sacha at email@hidden wrote:
>
So here's an updated version, now that I've had a chance to test it
>
and make sure it basically works (although there might still be other
>
bugs floating around).
Thank you, Louis!
I also wrote a NSString extension as follows. :-)
Although I am going to test it now.
- (NSString *)relativePathForBasePath:(NSString *)basePath
{
NSArray *myPathComponents = [self pathComponents];
NSArray *basePathComponents = [basePath pathComponents];
int commonIndex, index;
NSString *resutPath;
commonIndex = -1;
for( index=0; index < [basePathComponents count]; index++ )
{
if( ![[basePathComponents objectAtIndex:index]
isEqualToString:[myPathComponents objectAtIndex:index]] ) break;
commonIndex++;
}
if( commonIndex == -1 )
{
// another volume
resutPath = [NSString stringWithString:self];
}
else if( commonIndex == [basePathComponents count] -1 )
{
// in base directory
resutPath=[NSString stringWithString:@""];
for( index=commonIndex+1; index < [myPathComponents count]; index++ )
{
resutPath = [resutPath
stringByAppendingPathComponent:[myPathComponents objectAtIndex:index]];
}
}
else
{
// outside of base directory
resutPath=[NSString stringWithString:@""];
for( index=commonIndex; index< [basePathComponents count]-1; index++ )
{
resutPath=[resutPath stringByAppendingString:@"../"];
}
for( index=commonIndex+1; index < [myPathComponents count]; index++ )
{
resutPath = [resutPath
stringByAppendingPathComponent:[myPathComponents objectAtIndex:index]];
}
}
return resutPath;
}
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.