From 145a80f11f0f4da1e435b28e9324bed6ce643498 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 27 Oct 2015 17:19:35 +0000 Subject: [PATCH] Fix for builds with JUCE_STRING_UTF_TYPE = 32 --- .../juce_core/native/juce_linux_CommonFile.cpp | 4 ++-- modules/juce_core/text/juce_NewLine.h | 7 ++++--- modules/juce_core/text/juce_String.cpp | 18 ++++++++++++++++++ modules/juce_core/text/juce_String.h | 7 +++++++ modules/juce_core/text/juce_StringRef.h | 4 +--- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/modules/juce_core/native/juce_linux_CommonFile.cpp b/modules/juce_core/native/juce_linux_CommonFile.cpp index 924d5e9050..5f6c93b72c 100644 --- a/modules/juce_core/native/juce_linux_CommonFile.cpp +++ b/modules/juce_core/native/juce_linux_CommonFile.cpp @@ -58,10 +58,10 @@ bool File::isHidden() const return getFileName().startsWithChar ('.'); } -static String getLinkedFile (StringRef file) +static String getLinkedFile (const String& file) { HeapBlock buffer (8194); - const int numBytes = (int) readlink (file.text, buffer, 8192); + const int numBytes = (int) readlink (file.toRawUTF8(), buffer, 8192); return String::fromUTF8 (buffer, jmax (0, numBytes)); }; diff --git a/modules/juce_core/text/juce_NewLine.h b/modules/juce_core/text/juce_NewLine.h index 0d310cddb2..d056470432 100644 --- a/modules/juce_core/text/juce_NewLine.h +++ b/modules/juce_core/text/juce_NewLine.h @@ -78,9 +78,10 @@ extern NewLine newLine; @endcode */ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, const NewLine&); +JUCE_API String JUCE_CALLTYPE operator+ (const NewLine&, const NewLine&); + +inline String operator+ (String s1, const NewLine&) { return s1 += NewLine::getDefault(); } +inline String& operator+= (String& s1, const NewLine&) { return s1 += NewLine::getDefault(); } -#if JUCE_STRING_UTF_TYPE != 8 && ! defined (DOXYGEN) - inline String operator+ (String s1, const NewLine&) { return s1 += NewLine::getDefault(); } -#endif #endif // JUCE_NEWLINE_H_INCLUDED diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index cf9336d726..d0ecaae33b 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -365,6 +365,7 @@ String::String (const CharPointer_UTF16 start, const CharPointer_UTF16 end) : t String::String (const CharPointer_UTF32 start, const CharPointer_UTF32 end) : text (StringHolder::createFromCharPointer (start, end)) {} String::String (const std::string& s) : text (StringHolder::createFromFixedLength (s.data(), s.size())) {} +String::String (StringRef s) : text (StringHolder::createFromCharPointer (s.text)) {} String String::charToString (const juce_wchar character) { @@ -768,6 +769,11 @@ String& String::operator+= (const String& other) return *this; } +String& String::operator+= (StringRef other) +{ + return operator+= (String (other)); +} + String& String::operator+= (const char ch) { const char asString[] = { ch, 0 }; @@ -843,6 +849,7 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t s2) JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const char* const s2) { return s1 += s2; } JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t* const s2) { return s1 += s2; } JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const String& s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, StringRef s2) { return s1 += s2; } JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const int number) { return s1 += number; } JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const short number) { return s1 += (int) number; } @@ -879,6 +886,11 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, const NewLine&) return string1 += NewLine::getDefault(); } +JUCE_API String JUCE_CALLTYPE operator+ (const NewLine&, const NewLine&) +{ + return String (NewLine::getDefault()) + NewLine::getDefault(); +} + //============================================================================== int String::indexOfChar (const juce_wchar character) const noexcept { @@ -2308,6 +2320,10 @@ public: expect (String ("abcdEFGH").toLowerCase() == String ("abcdefgh")); expect (String ("abcdEFGH").toUpperCase() == String ("ABCDEFGH")); + expect (String (StringRef ("abc")) == "abc"); + expect (String (StringRef ("abc")) == StringRef ("abc")); + expect (String ("abc") + StringRef ("def") == "abcdef"); + String s2 ("123"); s2 << ((int) 4) << ((short) 5) << "678" << L"9" << '0'; s2 += "xyz"; @@ -2316,6 +2332,8 @@ public: expect (s2 == "1234567890xyz123"); s2 += (int64) 123; expect (s2 == "1234567890xyz123123"); + s2 << StringRef ("def"); + expect (s2 == "1234567890xyz123123def"); beginTest ("Numeric conversions"); expect (String::empty.getIntValue() == 0); diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 5c2a89f1c3..a93a46cc8a 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -136,6 +136,9 @@ public: /** Creates a string from a UTF-8 encoded std::string. */ String (const std::string&); + /** Creates a string from a StringRef */ + String (StringRef); + //============================================================================== /** Creates a string from a single character. */ static String charToString (juce_wchar character); @@ -202,6 +205,8 @@ public: String& operator+= (const char* textToAppend); /** Appends another string at the end of this one. */ String& operator+= (const wchar_t* textToAppend); + /** Appends another string at the end of this one. */ + String& operator+= (StringRef textToAppend); /** Appends a decimal number at the end of this string. */ String& operator+= (int numberToAppend); /** Appends a decimal number at the end of this string. */ @@ -1289,6 +1294,8 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, const char* string2) JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, const wchar_t* string2); /** Appends a string to the end of the first one. */ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, const String& string2); +/** Appends a string to the end of the first one. */ +JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, StringRef string2); /** Appends a decimal number at the end of a string. */ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, short number); diff --git a/modules/juce_core/text/juce_StringRef.h b/modules/juce_core/text/juce_StringRef.h index 3c17600ab4..bd0e142324 100644 --- a/modules/juce_core/text/juce_StringRef.h +++ b/modules/juce_core/text/juce_StringRef.h @@ -131,8 +131,6 @@ JUCE_API bool JUCE_CALLTYPE operator== (const String& string1, StringRef string2 /** Case-sensitive comparison of two strings. */ JUCE_API bool JUCE_CALLTYPE operator!= (const String& string1, StringRef string2) noexcept; -#if JUCE_STRING_UTF_TYPE != 8 && ! defined (DOXYGEN) - inline String operator+ (String s1, StringRef s2) { return s1 += String (s2.text); } -#endif +inline String operator+ (String s1, StringRef s2) { return s1 += String (s2.text); } #endif // JUCE_STRINGREF_H_INCLUDED