`File::getFileName()` encoding diacritic marks error

Hello,
I create File with String parameter. Like:
File myFile = File(myString);

Where myString contains diacritic marks. For example “ó”.

And when I later get file name with method File::getFileName() I get the same string. They looks exactly the same in debuger. But comparing them with equalsIgnoreCase() always gives me false.

I don’t know why and how to repair it?

I tried to debug in for loop whole strings with operator [].
Like that:
char myStringChar = myString[i];
char fileStringChar = myFile.getFileName()[i];

And for letter “ó” myStringChar is straight “o”. So it removed diacritic mark.
But what is more strange the same letter in fileStringChar is something like that “\xc3”.

How to handle it? And how to be sure it would work on Windows and OSX.
Now I don’t know how it works on Windows. And that behaviour is on OSX Big Sure on Macbook Pro with new M1 processor (maybe it has something to do with that issue)?

For any help great thanks in advance.

A couple of things come to mind:

  • A File always holds an absolute path, so if you construct myFile from myString, this implies that myString holds an absolute path. However myFile.getFileName() will just return the name of the file (everying after the last path separator). I think it’s unlikely that myString and myFile.getFileName() would match for this reason (unless you’re changing the value of myString between initialising myFile and comparing myString with myFile). If you want to find the full path, use File::getFullPathName().
  • String::operator[] returns a juce_wchar which is different from a char. If you assign myString[i] to a char before doing the comparisons, you’ll truncate the value and the results will be meaningless. If you’re using the Projucer, you can enable “Add Recommended Compiler Warning Flags” in the exporter settings so that the compiler will emit warnings about this sort of thing.
1 Like

Hello,
great thanks for your help.