• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Conversion from an absolute URL to relative
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: Conversion from an absolute URL to relative (From: "Louis C. Sacha" <email@hidden>)

  • Prev by Date: Re: Privileged write to file
  • Next by Date: Re: Privileged write to file
  • Previous by thread: Re: Conversion from an absolute URL to relative
  • Next by thread: HElp with NSResponder
  • Index(es):
    • Date
    • Thread