String::replaceCharacters crash with accents

I’m having a very simple code crashing in juce functions :

String test = String("Test").replaceCharacters("à", "a");
will crash at juce_CharPointer_UTF8.h line 170

The same without the accent
String test = String("Test").replaceCharacters("a", "b");
will work.

Question is, what is the best practice then to convert all accents and special chars into [a-zA-Z0-9_] range (converting all the special chars with ‘_’ and all convertible accent with their normal letter correspondance).

Thanks !

This actually works in Xcode but is not a reliable way to encode those characters:

int main (int argc, char* argv[])
{
    String test = String("Taste").replaceCharacters("a", "à");
    Logger::outputDebugString (test);
    return 0;
}

I get:

JUCE v5.4.3
Tàste
Program ended with exit code: 0

You need to encode your accented characters using UTF-8 escape characters. There’s a tool in the Tools menu in the Projucer to help with that.

So you can then do:

String test = String ("Taste").replaceCharacters ("a", CharPointer_UTF8 ("\xc3\xa0"));

For your second question, in URL there is a static method to urlEncode, called addEscapeChars(), that uses the ugly web-standardised encodings.

Would be nice to have a human readable version too, that replaces ä => ae etc. but that list will probably become very long, considering all possible languages…
Maybe that exists, but I remember we had this topic similar lately with no conclusive answer

Thank you for that !
I’ll check that soon