Reputation: 35963
I am compiling a code segment using something like this:
char* filename = (char*) malloc( fileInfo.size_filename +1 );
unzGetCurrentFileInfo(_unzFile, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
filename[fileInfo.size_filename] = '\0';
NSString * strPath = [NSString stringWithCString:filename];
but stringWithCString is deprecated. I am supposed to change that to
NSString * strPath = [NSString stringWithCString:filename encoding:????];
this filename as the name says represents entries on the file system, files and directories. How do I know the encoding filename is using? I mean, I can put UTF-8, but who knows which encoding users around the world will be using. If I choose any encoding I will be limiting that.
How do I solve that to put the correct encoding for each user.
thanks
Upvotes: 0
Views: 358
Reputation: 43472
Actually, for C paths, you want something a bit uglier:
NSString *strPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:filename length:strlen(filename)];
And to go the other way:
const char *cPath = [nsFilename fileSystemRepresentation];
Upvotes: 4