mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Fixes for builds using utf-32 string storage.
This commit is contained in:
parent
30fbdc7eb1
commit
c54ca1037d
4 changed files with 31 additions and 8 deletions
|
|
@ -83,7 +83,7 @@ public:
|
|||
const String::CharPointerType getCharPointer() const noexcept { return name; }
|
||||
|
||||
/** Returns this identifier as a StringRef. */
|
||||
operator StringRef() const noexcept { return name.getAddress(); }
|
||||
operator StringRef() const noexcept { return name; }
|
||||
|
||||
/** Returns true if this Identifier is not null */
|
||||
bool isValid() const noexcept { return name.getAddress() != nullptr; }
|
||||
|
|
|
|||
|
|
@ -738,15 +738,20 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const double number)
|
|||
|
||||
JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
|
||||
{
|
||||
const size_t numBytes = text.getNumBytesAsUTF8();
|
||||
return operator<< (stream, StringRef (text));
|
||||
}
|
||||
|
||||
JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, StringRef text)
|
||||
{
|
||||
const size_t numBytes = CharPointer_UTF8::getBytesRequiredFor (text.text);
|
||||
|
||||
#if (JUCE_STRING_UTF_TYPE == 8)
|
||||
stream.write (text.getCharPointer().getAddress(), numBytes);
|
||||
stream.write (text.text.getAddress(), numBytes);
|
||||
#else
|
||||
// (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
|
||||
// if lots of large, persistent strings were to be written to streams).
|
||||
HeapBlock<char> temp (numBytes + 1);
|
||||
CharPointer_UTF8 (temp).writeAll (text.getCharPointer());
|
||||
CharPointer_UTF8 (temp).writeAll (text.text);
|
||||
stream.write (temp, numBytes);
|
||||
#endif
|
||||
|
||||
|
|
@ -2047,12 +2052,21 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
|
|||
#endif
|
||||
|
||||
//==============================================================================
|
||||
StringRef::StringRef() noexcept : text ("\0\0\0")
|
||||
StringRef::StringRef() noexcept : text ((const String::CharPointerType::CharType*) "\0\0\0")
|
||||
{
|
||||
}
|
||||
|
||||
StringRef::StringRef (const String::CharPointerType::CharType* stringLiteral) noexcept : text (stringLiteral)
|
||||
StringRef::StringRef (const char* stringLiteral) noexcept
|
||||
#if JUCE_STRING_UTF_TYPE != 8
|
||||
: text (nullptr), stringCopy (stringLiteral)
|
||||
#else
|
||||
: text (stringLiteral)
|
||||
#endif
|
||||
{
|
||||
#if JUCE_STRING_UTF_TYPE != 8
|
||||
text = stringCopy.getCharPointer();
|
||||
#endif
|
||||
|
||||
jassert (stringLiteral != nullptr); // This must be a valid string literal, not a null pointer!!
|
||||
|
||||
#if JUCE_NATIVE_WCHAR_IS_UTF8
|
||||
|
|
@ -2080,6 +2094,7 @@ StringRef::StringRef (String::CharPointerType stringLiteral) noexcept : text (s
|
|||
|
||||
StringRef::StringRef (const String& string) noexcept : text (string.getCharPointer()) {}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
|
|
|||
|
|
@ -1337,5 +1337,8 @@ std::basic_ostream <wchar_t, traits>& JUCE_CALLTYPE operator<< (std::basic_ostre
|
|||
/** Writes a string to an OutputStream as UTF8. */
|
||||
JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& stringToWrite);
|
||||
|
||||
/** Writes a string to an OutputStream as UTF8. */
|
||||
JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, StringRef stringToWrite);
|
||||
|
||||
|
||||
#endif // JUCE_STRING_H_INCLUDED
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#ifndef JUCE_STRINGREF_H_INCLUDED
|
||||
#define JUCE_STRINGREF_H_INCLUDED
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A simple class for holding temporary references to a string literal or String.
|
||||
|
|
@ -71,7 +70,7 @@ public:
|
|||
ensure that the data does not change during the lifetime of the StringRef.
|
||||
Note that this pointer not be null!
|
||||
*/
|
||||
StringRef (const String::CharPointerType::CharType* stringLiteral) noexcept;
|
||||
StringRef (const char* stringLiteral) noexcept;
|
||||
|
||||
/** Creates a StringRef from a raw char pointer.
|
||||
The StringRef object does NOT take ownership or copy this data, so you must
|
||||
|
|
@ -115,6 +114,12 @@ public:
|
|||
//==============================================================================
|
||||
/** The text that is referenced. */
|
||||
String::CharPointerType text;
|
||||
|
||||
#if JUCE_STRING_UTF_TYPE != 8 && ! defined (DOXYGEN)
|
||||
// Sorry, non-UTF8 people, you're unable to take advantage of StringRef, because
|
||||
// you've chosen a character encoding that doesn't match C++ string literals.
|
||||
String stringCopy;
|
||||
#endif
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue