From b3390dabc9f8ced7c1eee8270faf02453da52fe9 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 3 May 2018 10:59:39 +0100 Subject: [PATCH] Added a constructor to StringRef that takes a std::string --- modules/juce_core/text/juce_String.cpp | 3 ++- modules/juce_core/text/juce_StringRef.h | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index c7eddc0218..55dea1be34 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -2207,7 +2207,8 @@ StringRef::StringRef (String::CharPointerType stringLiteral) noexcept : text (s jassert (stringLiteral.getAddress() != nullptr); // This must be a valid string literal, not a null pointer!! } -StringRef::StringRef (const String& string) noexcept : text (string.getCharPointer()) {} +StringRef::StringRef (const String& string) noexcept : text (string.getCharPointer()) {} +StringRef::StringRef (const std::string& string) : StringRef (string.c_str()) {} //============================================================================== diff --git a/modules/juce_core/text/juce_StringRef.h b/modules/juce_core/text/juce_StringRef.h index 2c171f4614..82bf4982d4 100644 --- a/modules/juce_core/text/juce_StringRef.h +++ b/modules/juce_core/text/juce_StringRef.h @@ -81,6 +81,13 @@ public: */ StringRef (const String& string) noexcept; + /** Creates a StringRef from a String. + The StringRef object does NOT take ownership or copy the data from the std::string, + so you must ensure that the source string object is not modified or deleted during + the lifetime of the StringRef. + */ + StringRef (const std::string& string); + /** Creates a StringRef pointer to an empty string. */ StringRef() noexcept;