Links with ../ and /
Links with ../ and /
- Subject: Links with ../ and /
- From: "Mr. Gecko" <email@hidden>
- Date: Wed, 19 Nov 2008 23:13:29 -0600
How do I handle links with ../ for previous directory and / for front
of url.
I am current;y doing it with
NSArray *linkArray = [[self replace:@"http://" with:@"" source:[self
replace:@"https://" with:@"" source:link]]
componentsSeparatedByString:@"/"];
if ([linkArray count]!=0) {
NSString *thisDomain = [linkArray objectAtIndex:0];
if (![link hasPrefix:@"http://"] && ![link hasPrefix:@"https://"]) {
NSString *newLink = @"";
thisDomain = [urlArray objectAtIndex:0];
for (l=0; l<[linkArray count]; l++) {
if ([[linkArray objectAtIndex:l] isEqualToString:@".."]) {
newLink = [newLink stringByAppendingFormat:@"%@/", [urlArray
objectAtIndex:l+1]];
} else {
newLink = [newLink stringByAppendingFormat:@"%@%@", [linkArray
objectAtIndex:l], ([linkArray count]==l+2 ? @"" : @"/")];
}
}
link = [NSString stringWithFormat:@"%@%@%@", ([url
hasPrefix:@"http://"] ? @"http://" : @"https://"), [urlArray
objectAtIndex:0], ([newLink hasPrefix:@"/"] ? newLink : [NSString
stringWithFormat:@"/%@", newLink])];
}
}
This does have some problems though. if it is a file it would still
trail with a /.
thanks for helping me,
Mr. Gecko
_______________________________________________
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