Usage of String::toRawUTF8()

Given that juce::String uses UTF-8 encoding internally, is there any difference between using toRawUTF8() vs the simple getCharPointer() ?

Thanks

You have control over which underlying UTF char pointer is used (at compile time) - between 8, 16, and 32 - meaning getCharPointer might return CharPointer_UTF32 or CharPointer_UTF16 instead of the default CharPointer_UTF8. Notice that it returns a String::CharPointerType.

Obviously this is very specialised and there are few circumstances where changing this matters. For example, I’ve had to change the UTF type in the past when writing a complex text layout system using NVPR: as part of the interfacing with ICU’s i18n text, many mappings have to happen in UTF-16 - which also reduced glyph and grapheme look-up times in our case.

2 Likes