Created
January 20, 2015 19:00
-
-
Save pxpgraphics/9d7495a25e3903ff91ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)normalizeString:(NSString *)string | |
{ | |
NSString *normalizedString = [[string copy] stringByStandardizingPath]; // copy to keep thread-safe; | |
if ([normalizedString hasPrefix:@".."]) { | |
normalizedString = [normalizedString substringFromIndex:2]; | |
} | |
if ([normalizedString containsString:@"/../"]) { | |
NSArray *components = [normalizedString componentsSeparatedByString:@"/../"]; | |
NSMutableArray *tempComponents = [components mutableCopy]; | |
for (NSString *component in components) { | |
if (![component containsString:@"/"]) { | |
continue; | |
} | |
NSRange range = [component rangeOfString:@"/"]; | |
NSString *string = [component substringToIndex:range.location]; | |
[tempComponents replaceObjectAtIndex:[components indexOfObject:component] withObject:string]; | |
} | |
components = [tempComponents copy]; | |
normalizedString = [components componentsJoinedByString:@"/"]; | |
} | |
return normalizedString; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment