We noticed that wchar_t is well supported but the to and from wstring are not implemented. I think the following would suffice (I haven’t added any tests or anything though). Would this be a useful addition?
diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp
index 1681c2c21..3c8b1136f 100644
--- a/modules/juce_core/text/juce_String.cpp
+++ b/modules/juce_core/text/juce_String.cpp
@@ -365,8 +365,9 @@ String::String (CharPointer_UTF8 start, CharPointer_UTF8 end) : text (StringH
String::String (CharPointer_UTF16 start, CharPointer_UTF16 end) : text (StringHolder::createFromCharPointer (start, end)) {}
String::String (CharPointer_UTF32 start, 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 (const std::string& s) : text (StringHolder::createFromFixedLength (s.data(), s.size())) {}^M
+String::String (const std::wstring& s) : text (StringHolder::createFromCharPointer (castToCharPointer_wchar_t (s.data()), s.size())) {}^M
+String::String (StringRef s) : text (StringHolder::createFromCharPointer (s.text)) {}^M
String String::charToString (juce_wchar character)
{
@@ -2089,6 +2090,11 @@ std::string String::toStdString() const
return std::string (toRawUTF8());
}
+std::wstring String::toStdWString() const^M
+{^M
+ return std::wstring (toWideCharPointer());^M
+}^M
+^M
//==============================================================================
template <class CharPointerType_Src, class CharPointerType_Dest>
struct StringCopier
diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h
index 3a5a52d2d..441ec992a 100644
--- a/modules/juce_core/text/juce_String.h
+++ b/modules/juce_core/text/juce_String.h
@@ -130,6 +130,9 @@ public:
/** Creates a string from a UTF-8 encoded std::string. */
String (const std::string&);
+ /** Creates a string from a wchar_t (UTF-16 or UTF-32) encoded std::wstring. */^M
+ String (const std::wstring&);^M
+^M
/** Creates a string from a StringRef */
String (StringRef);
@@ -1263,6 +1266,9 @@ public:
/** */
std::string toStdString() const;
+ /** */^M
+ std::wstring toStdWString() const;^M
+^M
//==============================================================================
/** Creates a String from a UTF-8 encoded buffer.
If the size is < 0, it'll keep reading until it hits a zero.