@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -12,12 +12,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ /* - * This file is also used for MS-DOS! Don't forget to #ifdef Windows-specific - * parts! + * This file is also used for MS-DOS and MiNT! Don't forget to #ifdef + * Windows-specific parts! */ #include "config.h" #import "OFString+PathAdditions.h" @@ -316,10 +316,31 @@ [ret makeImmutable]; return ret; } } + +- (OFString *)stringByAppendingPathExtension: (OFString *)extension +{ + if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"]) { + void *pool = objc_autoreleasePoolPush(); + OFMutableArray *components; + OFString *fileName, *ret; + + components = + [[self.pathComponents mutableCopy] autorelease]; + fileName = [components.lastObject + stringByAppendingFormat: @".%@", extension]; + [components replaceObjectAtIndex: components.count - 1 + withObject: fileName]; + + ret = [[OFString pathWithComponents: components] retain]; + objc_autoreleasePoolPop(pool); + return [ret autorelease]; + } else + return [self stringByAppendingFormat: @".%@", extension]; +} - (bool)of_isDirectoryPath { return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] || [OFFileURLHandler of_directoryExistsAtPath: self]);