@@ -53,10 +53,57 @@ * However, the MinGW version __strtod seems to be ok. */ #ifdef _WIN32 # define strtod __strtod #endif + +static OFString* +standardize_path(OFArray *components, OFString *currentDirectory, + OFString *parentDirectory, OFString *joinString) +{ + void *pool = objc_autoreleasePoolPush(); + OFMutableArray *array; + OFString *ret; + BOOL done = NO; + + array = [[components mutableCopy] autorelease]; + + while (!done) { + size_t i, length = [array count]; + + done = YES; + + for (i = 0; i < length; i++) { + id object = [array objectAtIndex: i]; + + if ([object isEqual: currentDirectory]) { + [array removeObjectAtIndex: i]; + done = NO; + + break; + } + + if ([object isEqual: parentDirectory]) { + [array removeObjectAtIndex: i]; + + if (i > 0) + [array removeObjectAtIndex: i - 1]; + + done = NO; + + break; + } + } + } + + ret = [[array componentsJoinedByString: joinString] retain]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +} + /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_Hashing_reference = 1; @@ -1764,10 +1811,23 @@ objc_autoreleasePoolPop(pool); return @"."; } + +- (OFString*)stringByStandardizingPath +{ + return standardize_path([self pathComponents], + OF_PATH_CURRENT_DIRECTORY, OF_PATH_PARENT_DIRECTORY, + OF_PATH_DELIMITER_STRING); +} + +- (OFString*)stringByStandardizingURLPath +{ + return standardize_path( [self componentsSeparatedByString: @"/"], + @".", @"..", @"/"); +} - (intmax_t)decimalValue { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString];