Form normalized paths from absolutes with ObjC

This commit is contained in:
Struma 2020-12-14 11:42:31 -05:00 committed by Roza
parent dffbe682f1
commit 45e224626e

View file

@ -7,7 +7,8 @@
#import <Foundation/Foundation.h>
#import "filesystemImpl.h"
#import "exception.h"
#import "util/exception.h"
#import "util/debugwriter.h"
#define PATHTONS(str) [NSFileManager.defaultManager stringWithFileSystemRepresentation:str length:strlen(str)]
@ -40,13 +41,12 @@ std::string filesystemImpl::getCurrentDirectory() {
}
std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool absolute) {
NSString *nspath = PATHTONS(path);
if (!nspath.isAbsolutePath && absolute) {
nspath = [NSURL fileURLWithPath: nspath].URLByStandardizingPath.path;
}
else {
nspath = nspath.stringByStandardizingPath;
NSString *nspath = [NSURL fileURLWithPath: PATHTONS(path)].URLByStandardizingPath.path;
NSString *pwd = [NSString stringWithFormat:@"%@/", NSFileManager.defaultManager.currentDirectoryPath];
if (!absolute) {
nspath = [nspath stringByReplacingOccurrencesOfString:pwd withString:@""];
}
Debug() << nspath.UTF8String;
return std::string(NSTOPATH(nspath));
}