@@ -58,10 +58,81 @@ @interface OFCharacterSet_URLQueryOrFragmentAllowed: OFCharacterSet_URLAllowedBase + (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet; @end + +#ifdef OF_HAVE_FILES +static OFString * +pathToURLPath(OFString *path) +{ +# if defined(OF_WINDOWS) || defined(OF_MSDOS) + path = [path stringByReplacingOccurrencesOfString: @"\\" + withString: @"/"]; + path = [path stringByPrependingString: @"/"]; +# elif defined(OF_AMIGAOS) + OFArray OF_GENERIC(OFString *) *components = [path pathComponents]; + OFMutableString *ret = [OFMutableString string]; + + for (OFString *component in components) { + if ([component length] == 0) + continue; + + if ([component isEqual: @"/"]) + [ret appendString: @"/.."]; + else { + [ret appendString: @"/"]; + [ret appendString: component]; + } + } + + [ret makeImmutable]; + + return ret; +# else + return path; +# endif +} + +static OFString * +URLPathToPath(OFString *path) +{ +# if defined(OF_WINDOWS) || defined(OF_MSDOS) + path = [path substringWithRange: of_range(1, [path length] - 1)]; + path = [path stringByReplacingOccurrencesOfString: @"/" + withString: @"\\"]; +# elif defined(OF_AMIGAOS) + OFMutableArray OF_GENERIC(OFString *) *components; + size_t count; + + path = [path substringWithRange: of_range(1, [path length] - 1)]; + components = [[[path + componentsSeparatedByString: @"/"] mutableCopy] autorelease]; + count = [components count]; + + for (size_t i = 0; i < count; i++) { + OFString *component = [components objectAtIndex: i]; + + if ([component isEqual: @"."]) { + [components removeObjectAtIndex: i]; + count--; + + i--; + continue; + } + + if ([component isEqual: @".."]) + [components replaceObjectAtIndex: i + withObject: @"/"]; + } + + return [OFString pathWithComponents: components]; +# else + return path; +# endif +} +#endif @interface OFCharacterSet_invertedSetWithPercent: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, of_unichar_t); @@ -607,10 +678,14 @@ #if defined(OF_WINDOWS) || defined(OF_MSDOS) isDirectory = ([path hasSuffix: @"\\"] || [path hasSuffix: @"/"] || [OFURLHandler_file of_directoryExistsAtPath: path]); +#elif defined(OF_AMIGAOS) + isDirectory = ([path hasSuffix: @"/"] || + [path hasSuffix: @":"] || + [OFURLHandler_file of_directoryExistsAtPath: path]); #else isDirectory = ([path hasSuffix: @"/"] || [OFURLHandler_file of_directoryExistsAtPath: path]); #endif @@ -641,15 +716,11 @@ path = [currentDirectoryPath stringByAppendingPathComponent: path]; path = [path stringByStandardizingPath]; } -# if defined(OF_WINDOWS) || defined(OF_DJGPP) - path = [path stringByReplacingOccurrencesOfString: @"\\" - withString: @"/"]; - path = [path stringByPrependingString: @"/"]; -# endif + path = pathToURLPath(path); if (isDirectory && ![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; _URLEncodedScheme = @"file"; @@ -962,15 +1033,11 @@ if ([path hasSuffix: @"/"]) path = [path substringWithRange: of_range(0, [path length] - 1)]; -#if defined(OF_WINDOWS) || defined(OF_MSDOS) - path = [path substringWithRange: of_range(1, [path length] - 1)]; - path = [path stringByReplacingOccurrencesOfString: @"/" - withString: @"\\"]; -#endif + path = URLPathToPath(path); [path retain]; objc_autoreleasePoolPop(pool);