Browse Source

Added String methods to create/return a std::string, and also String::toRawUTF8 method.

tags/2021-05-28
jules 13 years ago
parent
commit
b4382bad62
14 changed files with 55 additions and 25 deletions
  1. +1
    -1
      extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp
  2. +1
    -1
      modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp
  3. +1
    -1
      modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp
  4. +1
    -1
      modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp
  5. +5
    -5
      modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
  6. +1
    -3
      modules/juce_core/maths/juce_MathsFunctions.h
  7. +1
    -1
      modules/juce_core/native/juce_mac_Files.mm
  8. +1
    -1
      modules/juce_core/native/juce_mac_SystemStats.mm
  9. +1
    -1
      modules/juce_core/native/juce_posix_SharedCode.h
  10. +4
    -4
      modules/juce_core/native/juce_win32_Network.cpp
  11. +2
    -2
      modules/juce_core/network/juce_URL.cpp
  12. +13
    -0
      modules/juce_core/text/juce_String.cpp
  13. +21
    -2
      modules/juce_core/text/juce_String.h
  14. +2
    -2
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp

+ 1
- 1
extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp View File

@@ -180,7 +180,7 @@ namespace CodeHelpers
String addEscapeChars (const String& s) String addEscapeChars (const String& s)
{ {
MemoryOutputStream out; MemoryOutputStream out;
writeEscapeChars (out, s.toUTF8().getAddress(), -1, -1, false, true, true);
writeEscapeChars (out, s.toRawUTF8(), -1, -1, false, true, true);
return out.toUTF8(); return out.toUTF8();
} }


+ 1
- 1
modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp View File

@@ -418,7 +418,7 @@ private:
const String s (metadata [name]); const String s (metadata [name]);
if (s.isNotEmpty()) if (s.isNotEmpty())
vorbis_comment_add_tag (&vc, vorbisName, const_cast <char*> (s.toUTF8().getAddress()));
vorbis_comment_add_tag (&vc, vorbisName, const_cast <char*> (s.toRawUTF8()));
} }
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OggWriter) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OggWriter)


+ 1
- 1
modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp View File

@@ -688,7 +688,7 @@ struct AAXClasses
{ {
AAX_IParameter* parameter AAX_IParameter* parameter
= new AAX_CParameter<float> (IndexAsParamID (parameterIndex), = new AAX_CParameter<float> (IndexAsParamID (parameterIndex),
audioProcessor.getParameterName (parameterIndex).toUTF8().getAddress(),
audioProcessor.getParameterName (parameterIndex).toRawUTF8(),
audioProcessor.getParameter (parameterIndex), audioProcessor.getParameter (parameterIndex),
AAX_CLinearTaperDelegate<float, 0>(), AAX_CLinearTaperDelegate<float, 0>(),
AAX_CNumberDisplayDelegate<float, 3>(), AAX_CNumberDisplayDelegate<float, 3>(),


+ 1
- 1
modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp View File

@@ -926,7 +926,7 @@ public:
JucePlugin_RTASProductId, JucePlugin_RTASProductId,
JucePlugin_RTASCategory); JucePlugin_RTASCategory);
type->DefineTypeNames (createRTASName().toUTF8().getAddress());
type->DefineTypeNames (createRTASName().toRawUTF8());
type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k); type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k);
type->DefineStemFormats (getFormatForChans (channelConfigs [i][0] != 0 ? channelConfigs [i][0] : channelConfigs [i][1]), type->DefineStemFormats (getFormatForChans (channelConfigs [i][0] != 0 ? channelConfigs [i][0] : channelConfigs [i][1]),


+ 5
- 5
modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp View File

@@ -33,7 +33,7 @@
#if JUCE_MAC #if JUCE_MAC
static bool makeFSRefFromPath (FSRef* destFSRef, const String& path) static bool makeFSRefFromPath (FSRef* destFSRef, const String& path)
{ {
return FSPathMakeRef (reinterpret_cast <const UInt8*> (path.toUTF8().getAddress()), destFSRef, 0) == noErr;
return FSPathMakeRef (reinterpret_cast <const UInt8*> (path.toRawUTF8()), destFSRef, 0) == noErr;
} }
#endif #endif
@@ -493,7 +493,7 @@ public:
if (file.hasFileExtension (".vst")) if (file.hasFileExtension (".vst"))
{ {
const char* const utf8 = file.getFullPathName().toUTF8().getAddress();
const char* const utf8 = file.getFullPathName().toRawUTF8();
if (CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8, if (CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
strlen (utf8), file.isDirectory())) strlen (utf8), file.isDirectory()))
@@ -556,7 +556,7 @@ public:
{ {
FSRef fn; FSRef fn;
if (FSPathMakeRef ((UInt8*) file.getFullPathName().toUTF8().getAddress(), &fn, 0) == noErr)
if (FSPathMakeRef ((UInt8*) file.getFullPathName().toRawUTF8(), &fn, 0) == noErr)
{ {
resFileId = FSOpenResFile (&fn, fsRdPerm); resFileId = FSOpenResFile (&fn, fsRdPerm);
@@ -1245,7 +1245,7 @@ public:
if (index == getCurrentProgram()) if (index == getCurrentProgram())
{ {
if (getNumPrograms() > 0 && newName != getCurrentProgramName()) if (getNumPrograms() > 0 && newName != getCurrentProgramName())
dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toUTF8().getAddress(), 0.0f);
dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toRawUTF8(), 0.0f);
} }
else else
{ {
@@ -1834,7 +1834,7 @@ private:
#if JUCE_MAC #if JUCE_MAC
return (VstIntPtr) (void*) &module->parentDirFSSpec; return (VstIntPtr) (void*) &module->parentDirFSSpec;
#else #else
return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8().getAddress();
return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toRawUTF8();
#endif #endif
} }


+ 1
- 3
modules/juce_core/maths/juce_MathsFunctions.h View File

@@ -300,13 +300,11 @@ inline int64 abs64 (const int64 n) noexcept
//============================================================================== //==============================================================================
/** A predefined value for Pi, at double-precision. /** A predefined value for Pi, at double-precision.
@see float_Pi @see float_Pi
*/ */
const double double_Pi = 3.1415926535897932384626433832795; const double double_Pi = 3.1415926535897932384626433832795;
/** A predefined value for Pi, at sngle-precision.
/** A predefined value for Pi, at single-precision.
@see double_Pi @see double_Pi
*/ */
const float float_Pi = 3.14159265358979323846f; const float float_Pi = 3.14159265358979323846f;


+ 1
- 1
modules/juce_core/native/juce_mac_Files.mm View File

@@ -91,7 +91,7 @@ namespace FileHelpers
FSRef ref; FSRef ref;
LSItemInfoRecord info; LSItemInfoRecord info;
return FSPathMakeRefWithOptions ((const UInt8*) path.toUTF8().getAddress(), kFSPathMakeRefDoNotFollowLeafSymlink, &ref, 0) == noErr
return FSPathMakeRefWithOptions ((const UInt8*) path.toRawUTF8(), kFSPathMakeRefDoNotFollowLeafSymlink, &ref, 0) == noErr
&& LSCopyItemInfoForRef (&ref, kLSRequestBasicFlagsOnly, &info) == noErr && LSCopyItemInfoForRef (&ref, kLSRequestBasicFlagsOnly, &info) == noErr
&& (info.flags & kLSItemInfoIsInvisible) != 0; && (info.flags & kLSItemInfoIsInvisible) != 0;
#endif #endif


+ 1
- 1
modules/juce_core/native/juce_mac_SystemStats.mm View File

@@ -38,7 +38,7 @@ void Logger::outputDebugString (const String& text)
{ {
// Would prefer to use std::cerr here, but avoiding it for // Would prefer to use std::cerr here, but avoiding it for
// the moment, due to clang JIT linkage problems. // the moment, due to clang JIT linkage problems.
fputs (text.toUTF8().getAddress(), stderr);
fputs (text.toRawUTF8(), stderr);
fputs ("\n", stderr); fputs ("\n", stderr);
fflush (stderr); fflush (stderr);
} }


+ 1
- 1
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -880,7 +880,7 @@ void Thread::setCurrentThreadName (const String& name)
[[NSThread currentThread] setName: juceStringToNS (name)]; [[NSThread currentThread] setName: juceStringToNS (name)];
} }
#elif JUCE_LINUX #elif JUCE_LINUX
prctl (PR_SET_NAME, name.toUTF8().getAddress(), 0, 0, 0);
prctl (PR_SET_NAME, name.toRawUTF8(), 0, 0, 0);
#endif #endif
} }


+ 4
- 4
modules/juce_core/native/juce_win32_Network.cpp View File

@@ -408,15 +408,15 @@ bool Process::openEmailWithAttachments (const String& targetEmailAddress,
return false; return false;
MapiMessage message = { 0 }; MapiMessage message = { 0 };
message.lpszSubject = (LPSTR) emailSubject.toUTF8().getAddress();
message.lpszNoteText = (LPSTR) bodyText.toUTF8().getAddress();
message.lpszSubject = (LPSTR) emailSubject.toRawUTF8();
message.lpszNoteText = (LPSTR) bodyText.toRawUTF8();
MapiRecipDesc recip = { 0 }; MapiRecipDesc recip = { 0 };
recip.ulRecipClass = MAPI_TO; recip.ulRecipClass = MAPI_TO;
String targetEmailAddress_ (targetEmailAddress); String targetEmailAddress_ (targetEmailAddress);
if (targetEmailAddress_.isEmpty()) if (targetEmailAddress_.isEmpty())
targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address) targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
recip.lpszName = (LPSTR) targetEmailAddress_.toUTF8().getAddress();
recip.lpszName = (LPSTR) targetEmailAddress_.toRawUTF8();
message.nRecipCount = 1; message.nRecipCount = 1;
message.lpRecips = &recip; message.lpRecips = &recip;
@@ -429,7 +429,7 @@ bool Process::openEmailWithAttachments (const String& targetEmailAddress,
for (int i = 0; i < filesToAttach.size(); ++i) for (int i = 0; i < filesToAttach.size(); ++i)
{ {
files[i].nPosition = (ULONG) -1; files[i].nPosition = (ULONG) -1;
files[i].lpszPathName = (LPSTR) filesToAttach[i].toUTF8().getAddress();
files[i].lpszPathName = (LPSTR) filesToAttach[i].toRawUTF8();
} }
return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS; return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS;


+ 2
- 2
modules/juce_core/network/juce_URL.cpp View File

@@ -415,7 +415,7 @@ String URL::removeEscapeChars (const String& s)
// We need to operate on the string as raw UTF8 chars, and then recombine them into unicode // We need to operate on the string as raw UTF8 chars, and then recombine them into unicode
// after all the replacements have been made, so that multi-byte chars are handled. // after all the replacements have been made, so that multi-byte chars are handled.
Array<char> utf8 (result.toUTF8().getAddress(), (int) result.getNumBytesAsUTF8());
Array<char> utf8 (result.toRawUTF8(), (int) result.getNumBytesAsUTF8());
for (int i = 0; i < utf8.size(); ++i) for (int i = 0; i < utf8.size(); ++i)
{ {
@@ -440,7 +440,7 @@ String URL::addEscapeChars (const String& s, const bool isParameter)
const CharPointer_UTF8 legalChars (isParameter ? "_-.*!'()" const CharPointer_UTF8 legalChars (isParameter ? "_-.*!'()"
: ",$_-.*!'()"); : ",$_-.*!'()");
Array<char> utf8 (s.toUTF8().getAddress(), (int) s.getNumBytesAsUTF8());
Array<char> utf8 (s.toRawUTF8(), (int) s.getNumBytesAsUTF8());
for (int i = 0; i < utf8.size(); ++i) for (int i = 0; i < utf8.size(); ++i)
{ {


+ 13
- 0
modules/juce_core/text/juce_String.cpp View File

@@ -346,6 +346,8 @@ String::String (const CharPointer_UTF8& start, const CharPointer_UTF8& end) :
String::String (const CharPointer_UTF16& start, const CharPointer_UTF16& end) : text (StringHolder::createFromCharPointer (start, end)) {} String::String (const CharPointer_UTF16& start, const CharPointer_UTF16& end) : text (StringHolder::createFromCharPointer (start, end)) {}
String::String (const CharPointer_UTF32& start, const CharPointer_UTF32& end) : text (StringHolder::createFromCharPointer (start, end)) {} 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::charToString (const juce_wchar character) String String::charToString (const juce_wchar character)
{ {
String result (PreallocationBytes (CharPointerType::getBytesRequiredFor (character))); String result (PreallocationBytes (CharPointerType::getBytesRequiredFor (character)));
@@ -2011,11 +2013,21 @@ CharPointer_UTF8 String::toUTF8() const { return StringEncodingConverter <Char
CharPointer_UTF16 String::toUTF16() const { return StringEncodingConverter <CharPointerType, CharPointer_UTF16>::convert (*this); } CharPointer_UTF16 String::toUTF16() const { return StringEncodingConverter <CharPointerType, CharPointer_UTF16>::convert (*this); }
CharPointer_UTF32 String::toUTF32() const { return StringEncodingConverter <CharPointerType, CharPointer_UTF32>::convert (*this); } CharPointer_UTF32 String::toUTF32() const { return StringEncodingConverter <CharPointerType, CharPointer_UTF32>::convert (*this); }
const char* String::toRawUTF8() const
{
return toUTF8().getAddress();
}
const wchar_t* String::toWideCharPointer() const const wchar_t* String::toWideCharPointer() const
{ {
return StringEncodingConverter <CharPointerType, CharPointer_wchar_t>::convert (*this).getAddress(); return StringEncodingConverter <CharPointerType, CharPointer_wchar_t>::convert (*this).getAddress();
} }
std::string String::toStdString() const
{
return std::string (toRawUTF8());
}
//============================================================================== //==============================================================================
template <class CharPointerType_Src, class CharPointerType_Dest> template <class CharPointerType_Src, class CharPointerType_Dest>
struct StringCopier struct StringCopier
@@ -2251,6 +2263,7 @@ public:
expect (s3.indexOf (L"HIJK") == -1); expect (s3.indexOf (L"HIJK") == -1);
expect (s3.indexOfIgnoreCase ("hij") == 7); expect (s3.indexOfIgnoreCase ("hij") == 7);
expect (s3.indexOfIgnoreCase (L"hijk") == -1); expect (s3.indexOfIgnoreCase (L"hijk") == -1);
expect (s3.toStdString() == s3.toRawUTF8());
String s4 (s3); String s4 (s3);
s4.append (String ("xyz123"), 3); s4.append (String ("xyz123"), 3);


+ 21
- 2
modules/juce_core/text/juce_String.h View File

@@ -152,6 +152,9 @@ public:
/** Creates a string from an ASCII character string */ /** Creates a string from an ASCII character string */
String (const CharPointer_ASCII& text); String (const CharPointer_ASCII& text);
/** Creates a string from a UTF-8 encoded std::string. */
String (const std::string&);
//============================================================================== //==============================================================================
/** Creates a string from a single character. */ /** Creates a string from a single character. */
static String charToString (juce_wchar character); static String charToString (juce_wchar character);
@@ -1045,10 +1048,23 @@ public:
To find out how many bytes you need to store this string as UTF-8, you can call To find out how many bytes you need to store this string as UTF-8, you can call
CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer()) CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer())
@see getCharPointer, toUTF16, toUTF32
@see toRawUTF8, getCharPointer, toUTF16, toUTF32
*/ */
CharPointer_UTF8 toUTF8() const; CharPointer_UTF8 toUTF8() const;
/** Returns a pointer to a UTF-8 version of this string.
Because it returns a reference to the string's internal data, the pointer
that is returned must not be stored anywhere, as it can be deleted whenever the
string changes.
To find out how many bytes you need to store this string as UTF-8, you can call
CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer())
@see getCharPointer, toUTF8, toUTF16, toUTF32
*/
const char* toRawUTF8() const;
/** Returns a pointer to a UTF-16 version of this string. /** Returns a pointer to a UTF-16 version of this string.
Because it returns a reference to the string's internal data, the pointer Because it returns a reference to the string's internal data, the pointer
@@ -1086,6 +1102,9 @@ public:
*/ */
const wchar_t* toWideCharPointer() const; const wchar_t* toWideCharPointer() const;
/** */
std::string toStdString() const;
//============================================================================== //==============================================================================
/** Creates a String from a UTF-8 encoded buffer. /** Creates a String from a UTF-8 encoded buffer.
If the size is < 0, it'll keep reading until it hits a zero. If the size is < 0, it'll keep reading until it hits a zero.
@@ -1310,7 +1329,7 @@ JUCE_API bool JUCE_CALLTYPE operator<= (const String& string1, const String& str
template <class traits> template <class traits>
std::basic_ostream <char, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <char, traits>& stream, const String& stringToWrite) std::basic_ostream <char, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <char, traits>& stream, const String& stringToWrite)
{ {
return stream << stringToWrite.toUTF8().getAddress();
return stream << stringToWrite.toRawUTF8();
} }
/** This operator allows you to write a juce String directly to std output streams. /** This operator allows you to write a juce String directly to std output streams.


+ 2
- 2
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -883,7 +883,7 @@ public:
void setTitle (const String& title) void setTitle (const String& title)
{ {
XTextProperty nameProperty; XTextProperty nameProperty;
char* strings[] = { const_cast <char*> (title.toUTF8().getAddress()) };
char* strings[] = { const_cast <char*> (title.toRawUTF8()) };
ScopedXLock xlock; ScopedXLock xlock;
if (XStringListToTextProperty (strings, 1, &nameProperty)) if (XStringListToTextProperty (strings, 1, &nameProperty))
@@ -2527,7 +2527,7 @@ private:
xchangeProperty (evt.xselectionrequest.requestor, xchangeProperty (evt.xselectionrequest.requestor,
evt.xselectionrequest.property, evt.xselectionrequest.property,
targetType, 8, targetType, 8,
dragState.textOrFiles.toUTF8().getAddress(),
dragState.textOrFiles.toRawUTF8(),
dragState.textOrFiles.getNumBytesAsUTF8()); dragState.textOrFiles.getNumBytesAsUTF8());
} }


Loading…
Cancel
Save