• 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: Links with ../ and /
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Links with ../ and /


  • Subject: Re: Links with ../ and /
  • From: Rob Keniger <email@hidden>
  • Date: Thu, 20 Nov 2008 16:13:13 +1000


On 20/11/2008, at 3:13 PM, Mr. Gecko wrote:

How do I handle links with ../ for previous directory and / for front of url.


I'm currently doing this:

// Example: [ @"/a/b/c/d" relativePathTo: @"/a/e/f/g/h"] => @"../../e/ f/g/h".
- (NSString*) relativePathTo: (NSString*) endPath
{
if([self isEqual: endPath])
{
return [self lastPathComponent];
}
NSArray* startComponents = [self pathComponents];
NSArray* endComponents = [endPath pathComponents];
NSMutableArray* resultComponents = nil;
int prefixCount = 0;
if( ! [self isEqual: endPath] ){
int iLen = MIN([startComponents count], [endComponents count]);
for(prefixCount = 0; prefixCount < iLen && [[startComponents objectAtIndex: prefixCount] isEqual: [endComponents objectAtIndex: prefixCount]]; ++prefixCount){}
}
if(0 == prefixCount){
resultComponents = [NSMutableArray arrayWithArray: endComponents];
}else{
resultComponents = [NSMutableArray arrayWithArray: [endComponents subarrayWithRange: NSMakeRange(prefixCount, [endComponents count] - prefixCount)]];
int lifterCount = [startComponents count] - prefixCount;
if(1 == lifterCount){
//[resultComponents insertObject: @"." atIndex: 0];
}else{
--lifterCount;
int i = 0;
for(i = 0; i < lifterCount; ++i){
[resultComponents insertObject: @".." atIndex: 0];
}
}
}
return [NSString pathWithComponents: resultComponents];
}


--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Links with ../ and / (From: "Mr. Gecko" <email@hidden>)

  • Prev by Date: RE: Question about NSThread?
  • Next by Date: Fastest way to resize an image?
  • Previous by thread: Links with ../ and /
  • Next by thread: Re: Links with ../ and /
  • Index(es):
    • Date
    • Thread