JUCE_STRING_UTF_TYPE 32 build errors


Jules: "Damn, it's that UTF-32 guy again..."

Some default args in juce_XmlElement.h (StringRef encodingType = "UTF-8"):

cannot convert from 'const char [6]' to 'juce::StringRef'


Damn, it's you again.

I'll fix it, but did I ever ask why you're actually using that mode?

While doing some string work lately, I was trying to think of any situation where utf8 wouldn't be the best option, but couldn't think of one. I guess if you were doing a ton of time-critical win32 string calls, then just maybe you could make a vague argument for using utf16, but utf32..??


BTW I should mention that the only way to fix these errors involves disabling the new StringRef class in UTF-32 builds, so many more string copies will end up being made wherever a string literal is involved.

I really do recommend sticking with utf-8 unless you've profiled your app and actually measured its performance to be better. Seems highly unlikely to me that it'd ever be better to use the other encodings.


I'm doing multiple time-critical processing steps on potentially very large strings. Using UTF-32 is allowing me to avoid converting as well as allocating memory to cache a converted string to pass to different systems. I need to take every performance increase I can get.


Ok, fair enough!


I don't have those errors I mentioned anymore but now there are others. Something about ambiguous constructor or something. Not really sure what's going on as I see there are conversion operators in there. Adding a StringRef to a const String& also appears to be completely confusing the compiler in some instances.


If you can give me some examples, I'll see if there's anything I can add to help the compiler figure it out.


juce_File.cpp line 359: juce::String + juce::StringRef

'juce::String::operator bool' : cannot access private member declared in class 'juce::String'


juce_File.cpp line 649: juce::String + juce::StringRef

cannot convert parameter 1 from 'juce::CharPointer_UTF32::CharType' to 'juce::StringRef'


juce_StringArray.cpp line 198: 

'bool juce::String::equalsIgnoreCase(const juce::String &) throw() const' : cannot convert parameter 1 from 'juce::StringRef' to 'const juce::String &'


I can make it build and work by adding this to StringRef:

operator const String&() const noexcept                             { return stringCopy; }


I also had to modify the constructors for StringRef so that they populate StringRef::stringCopy and give its pointer to StringRef::text for that to work properly (juce_String.cpp line 2090). 

StringRef::StringRef (String::CharPointerType stringLiteral) noexcept
    : text (nullptr), stringCopy (stringLiteral)
    : text (stringLiteral)
    text = stringCopy.getCharPointer();
    jassert (stringLiteral.getAddress() != nullptr); // This must be a valid string literal, not a null pointer!!
StringRef::StringRef (const String& string) noexcept
    : text (nullptr), stringCopy (string)
    : text (string.getCharPointer())
    text = stringCopy.getCharPointer();


Ah, is this Visual Studio? I did test building it in UTF32 mode, but only with LLVM.. I'll check it with VC.


I'm using Visual Studio 2012.