diff --git a/extras/amalgamator/Builds/Linux/Makefile b/extras/amalgamator/Builds/Linux/Makefile index 4b80ce859b..eb3ea87325 100644 --- a/extras/amalgamator/Builds/Linux/Makefile +++ b/extras/amalgamator/Builds/Linux/Makefile @@ -5,6 +5,11 @@ ifndef CONFIG CONFIG=Debug endif +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := -march=native +endif + +# (this disables dependency generation if multiple architectures are set) DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD) ifeq ($(CONFIG),Debug) diff --git a/extras/amalgamator/JuceLibraryCode/AppConfig.h b/extras/amalgamator/JuceLibraryCode/AppConfig.h index febff521a2..da6a9214f4 100644 --- a/extras/amalgamator/JuceLibraryCode/AppConfig.h +++ b/extras/amalgamator/JuceLibraryCode/AppConfig.h @@ -34,4 +34,3 @@ //#define JUCE_SUPPORT_CARBON //#define JUCE_CHECK_MEMORY_LEAKS //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS -//#define JUCE_STRINGS_ARE_UNICODE diff --git a/extras/amalgamator/Source/Main.cpp b/extras/amalgamator/Source/Main.cpp index c43820312a..2e7d50b7cd 100644 --- a/extras/amalgamator/Source/Main.cpp +++ b/extras/amalgamator/Source/Main.cpp @@ -118,7 +118,7 @@ static bool parseFile (const File& rootFolder, if (lines.size() == 0) { - std::cout << "!! ERROR - input file was empty: " << (const char*) file.getFullPathName(); + std::cout << "!! ERROR - input file was empty: " << file.getFullPathName(); return false; } @@ -268,7 +268,7 @@ static bool munge (const File& templateFile, const File& targetFile, const Strin wildcards.trim(); wildcards.removeEmptyStrings(); - std::cout << "Building: " << (const char*) targetFile.getFullPathName() << "...\n"; + std::cout << "Building: " << targetFile.getFullPathName() << "...\n"; TemporaryFile temp (targetFile); ScopedPointer out (temp.getFile().createOutputStream (1024 * 128)); @@ -276,7 +276,7 @@ static bool munge (const File& templateFile, const File& targetFile, const Strin if (out == 0) { std::cout << "\n!! ERROR - couldn't write to the target file: " - << (const char*) temp.getFile().getFullPathName() << "\n\n"; + << temp.getFile().getFullPathName() << "\n\n"; return false; } @@ -302,7 +302,7 @@ static bool munge (const File& templateFile, const File& targetFile, const Strin if (! temp.overwriteTargetFileWithTemporary()) { std::cout << "\n!! ERROR - couldn't write to the target file: " - << (const char*) targetFile.getFullPathName() << "\n\n"; + << targetFile.getFullPathName() << "\n\n"; return false; } diff --git a/extras/audio plugin host/Builds/Linux/Makefile b/extras/audio plugin host/Builds/Linux/Makefile index b2a9ce6dea..f3921c8f2c 100644 --- a/extras/audio plugin host/Builds/Linux/Makefile +++ b/extras/audio plugin host/Builds/Linux/Makefile @@ -5,6 +5,11 @@ ifndef CONFIG CONFIG=Debug endif +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := -march=native +endif + +# (this disables dependency generation if multiple architectures are set) DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD) ifeq ($(CONFIG),Debug) diff --git a/extras/audio plugin host/JuceLibraryCode/AppConfig.h b/extras/audio plugin host/JuceLibraryCode/AppConfig.h index c50e5f63c9..049c80b159 100644 --- a/extras/audio plugin host/JuceLibraryCode/AppConfig.h +++ b/extras/audio plugin host/JuceLibraryCode/AppConfig.h @@ -34,4 +34,3 @@ //#define JUCE_SUPPORT_CARBON //#define JUCE_CHECK_MEMORY_LEAKS //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS -//#define JUCE_STRINGS_ARE_UNICODE diff --git a/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp b/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp index 29de4e0209..e90393a014 100644 --- a/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp +++ b/extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp @@ -849,7 +849,7 @@ private: void GetNameOfLength (char* name, int maxLength, OSType inControllerType) const { - juceFilter->getParameterName (index).copyToBuffer (name, maxLength); + juceFilter->getParameterName (index).copyToCString (name, maxLength); } long GetPriority() const { return kFicCooperativeTaskPriority; } @@ -864,7 +864,7 @@ private: void GetValueString (char* valueString, int maxLength, long value) const { - juceFilter->getParameterText (index).copyToBuffer (valueString, maxLength); + juceFilter->getParameterText (index).copyToCString (valueString, maxLength); } Cmn_Bool IsAutomatable() const @@ -890,7 +890,7 @@ public: JucePlugInGroup() { DefineManufacturerNamesAndID (JucePlugin_Manufacturer, JucePlugin_RTASManufacturerCode); - DefinePlugInNamesAndVersion (createRTASName(), JucePlugin_VersionCode); + DefinePlugInNamesAndVersion (createRTASName().toCString(), JucePlugin_VersionCode); #ifndef JUCE_DEBUG AddGestalt (pluginGestalt_IsCacheable); @@ -920,7 +920,7 @@ public: JucePlugin_RTASProductId, JucePlugin_RTASCategory); - type->DefineTypeNames (createRTASName()); + type->DefineTypeNames (createRTASName().toCString()); type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k); type->DefineStemFormats (getFormatForChans (channelConfigs [i][0] != 0 ? channelConfigs [i][0] : channelConfigs [i][1]), diff --git a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp index 1722cbfe67..63085208b3 100644 --- a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp +++ b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp @@ -479,13 +479,13 @@ public: //============================================================================== bool getEffectName (char* name) { - String (JucePlugin_Name).copyToBuffer (name, 64); + String (JucePlugin_Name).copyToCString (name, 64); return true; } bool getVendorString (char* text) { - String (JucePlugin_Manufacturer).copyToBuffer (text, 64); + String (JucePlugin_Manufacturer).copyToCString (text, 64); return true; } @@ -549,8 +549,8 @@ public: const String name (filter->getInputChannelName ((int) index)); - name.copyToBuffer (properties->label, kVstMaxLabelLen - 1); - name.copyToBuffer (properties->shortLabel, kVstMaxShortLabelLen - 1); + name.copyToCString (properties->label, kVstMaxLabelLen - 1); + name.copyToCString (properties->shortLabel, kVstMaxShortLabelLen - 1); if (speakerIn != kSpeakerArrEmpty) { @@ -577,8 +577,8 @@ public: const String name (filter->getOutputChannelName ((int) index)); - name.copyToBuffer (properties->label, kVstMaxLabelLen - 1); - name.copyToBuffer (properties->shortLabel, kVstMaxShortLabelLen - 1); + name.copyToCString (properties->label, kVstMaxLabelLen - 1); + name.copyToCString (properties->shortLabel, kVstMaxShortLabelLen - 1); if (speakerOut != kSpeakerArrEmpty) { @@ -938,14 +938,14 @@ public: void getProgramName (char* name) { if (filter != 0) - filter->getProgramName (filter->getCurrentProgram()).copyToBuffer (name, 24); + filter->getProgramName (filter->getCurrentProgram()).copyToCString (name, 24); } bool getProgramNameIndexed (VstInt32 category, VstInt32 index, char* text) { if (filter != 0 && ((unsigned int) index) < (unsigned int) filter->getNumPrograms()) { - filter->getProgramName (index).copyToBuffer (text, 24); + filter->getProgramName (index).copyToCString (text, 24); return true; } @@ -976,7 +976,7 @@ public: if (filter != 0) { jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters()); - filter->getParameterText (index).copyToBuffer (text, 24); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. + filter->getParameterText (index).copyToCString (text, 24); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. } } @@ -985,7 +985,7 @@ public: if (filter != 0) { jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters()); - filter->getParameterName (index).copyToBuffer (text, 16); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. + filter->getParameterName (index).copyToCString (text, 16); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. } } @@ -1321,7 +1321,7 @@ public: if (editorComp != 0) { #if ! JUCE_LINUX // linux hosts shouldn't be trusted! - if (! (canHostDo ("sizeWindow") && sizeWindow (newWidth, newHeight))) + if (! (canHostDo (const_cast ("sizeWindow")) && sizeWindow (newWidth, newHeight))) #endif { // some hosts don't support the sizeWindow call, so do it manually.. diff --git a/extras/audio plugins/wrapper/juce_PluginHostType.h b/extras/audio plugins/wrapper/juce_PluginHostType.h index 99563e770c..451268a0fb 100644 --- a/extras/audio plugins/wrapper/juce_PluginHostType.h +++ b/extras/audio plugins/wrapper/juce_PluginHostType.h @@ -137,10 +137,10 @@ private: return String ((const WCHAR*) buffer, size); #elif JUCE_MAC _NSGetExecutablePath ((char*) buffer, &size); - return String::fromUTF8 ((const JUCE_NAMESPACE::uint8*) buffer, size); + return String::fromUTF8 (buffer, size); #elif JUCE_LINUX readlink ("/proc/self/exe", (char*) buffer, size); - return String::fromUTF8 ((const JUCE_NAMESPACE::uint8*) buffer, size); + return String::fromUTF8 (buffer, size); #else #error #endif diff --git a/extras/binarybuilder/Builds/Linux/Makefile b/extras/binarybuilder/Builds/Linux/Makefile index 9db08119a0..4ad1fa9c6e 100644 --- a/extras/binarybuilder/Builds/Linux/Makefile +++ b/extras/binarybuilder/Builds/Linux/Makefile @@ -5,6 +5,11 @@ ifndef CONFIG CONFIG=Debug endif +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := -march=native +endif + +# (this disables dependency generation if multiple architectures are set) DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD) ifeq ($(CONFIG),Debug) diff --git a/extras/binarybuilder/JuceLibraryCode/AppConfig.h b/extras/binarybuilder/JuceLibraryCode/AppConfig.h index febff521a2..da6a9214f4 100644 --- a/extras/binarybuilder/JuceLibraryCode/AppConfig.h +++ b/extras/binarybuilder/JuceLibraryCode/AppConfig.h @@ -34,4 +34,3 @@ //#define JUCE_SUPPORT_CARBON //#define JUCE_CHECK_MEMORY_LEAKS //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS -//#define JUCE_STRINGS_ARE_UNICODE diff --git a/extras/example projects/Builds/Linux/Makefile b/extras/example projects/Builds/Linux/Makefile index b1c4bc2539..6b44bc3007 100644 --- a/extras/example projects/Builds/Linux/Makefile +++ b/extras/example projects/Builds/Linux/Makefile @@ -5,6 +5,11 @@ ifndef CONFIG CONFIG=Debug endif +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := -march=native +endif + +# (this disables dependency generation if multiple architectures are set) DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD) ifeq ($(CONFIG),Debug) diff --git a/extras/example projects/JuceLibraryCode/AppConfig.h b/extras/example projects/JuceLibraryCode/AppConfig.h index c351b66066..28003beb87 100644 --- a/extras/example projects/JuceLibraryCode/AppConfig.h +++ b/extras/example projects/JuceLibraryCode/AppConfig.h @@ -34,4 +34,3 @@ //#define JUCE_SUPPORT_CARBON //#define JUCE_CHECK_MEMORY_LEAKS //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS -//#define JUCE_STRINGS_ARE_UNICODE diff --git a/extras/juce demo/Builds/Linux/Makefile b/extras/juce demo/Builds/Linux/Makefile index 24de1cdcda..47f278be74 100644 --- a/extras/juce demo/Builds/Linux/Makefile +++ b/extras/juce demo/Builds/Linux/Makefile @@ -5,6 +5,11 @@ ifndef CONFIG CONFIG=Debug endif +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := -march=native +endif + +# (this disables dependency generation if multiple architectures are set) DEPFLAGS := $(if $(word 2, $(TARGET_ARCH)), , -MMD) ifeq ($(CONFIG),Debug) diff --git a/extras/juce demo/JuceLibraryCode/AppConfig.h b/extras/juce demo/JuceLibraryCode/AppConfig.h index a53467b44c..bff7ad93c1 100644 --- a/extras/juce demo/JuceLibraryCode/AppConfig.h +++ b/extras/juce demo/JuceLibraryCode/AppConfig.h @@ -34,4 +34,3 @@ //#define JUCE_SUPPORT_CARBON //#define JUCE_CHECK_MEMORY_LEAKS //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS -//#define JUCE_STRINGS_ARE_UNICODE diff --git a/extras/juce demo/JuceLibraryCode/BinaryData.cpp b/extras/juce demo/JuceLibraryCode/BinaryData.cpp index 80abe08f0d..35aeeae544 100644 --- a/extras/juce demo/JuceLibraryCode/BinaryData.cpp +++ b/extras/juce demo/JuceLibraryCode/BinaryData.cpp @@ -8,7 +8,7 @@ #include "BinaryData.h" -const char* BinaryData::getNamedResource (const char* resourceName, int& numBytes) throw() +const char* BinaryData::getNamedResource (const wchar_t* resourceName, int& numBytes) throw() { int hash = 0; while (*resourceName != 0) diff --git a/extras/juce demo/JuceLibraryCode/BinaryData.h b/extras/juce demo/JuceLibraryCode/BinaryData.h index a9dd8f6c3b..571257008e 100644 --- a/extras/juce demo/JuceLibraryCode/BinaryData.h +++ b/extras/juce demo/JuceLibraryCode/BinaryData.h @@ -24,5 +24,5 @@ namespace BinaryData // If you provide the name of one of the binary resource variables above, this function will // return the corresponding data and its size (or a null pointer if the name isn't found). - const char* getNamedResource (const char* resourceName, int& dataSizeInBytes) throw(); + const char* getNamedResource (const wchar_t* resourceName, int& dataSizeInBytes) throw(); } diff --git a/extras/juce demo/Source/demos/InterprocessCommsDemo.cpp b/extras/juce demo/Source/demos/InterprocessCommsDemo.cpp index 01f16ff8ae..021b0c222f 100644 --- a/extras/juce demo/Source/demos/InterprocessCommsDemo.cpp +++ b/extras/juce demo/Source/demos/InterprocessCommsDemo.cpp @@ -110,7 +110,7 @@ public: // The send button has been pressed, so write out the contents of the // text box to the socket or pipe, depending on which is active. const String text (sendText->getText()); - MemoryBlock messageData ((const char*) text, text.length()); + MemoryBlock messageData (text.toUTF8(), text.getNumBytesAsUTF8()); for (int i = activeConnections.size(); --i >= 0;) { diff --git a/juce.h b/juce.h index 623daa51c5..1f02a950b1 100644 --- a/juce.h +++ b/juce.h @@ -165,7 +165,7 @@ END_JUCE_NAMESPACE #define START_JUCE_APPLICATION(AppClass) \ int main (int argc, char* argv[]) \ { \ - return JUCE_NAMESPACE::JUCEApplication::main (argc, argv, new AppClass()); \ + return JUCE_NAMESPACE::JUCEApplication::main (argc, (const char**) argv, new AppClass()); \ } #elif JUCE_WINDOWS diff --git a/juce_Config.h b/juce_Config.h index 7f9c2f7dc9..0614cb57d0 100644 --- a/juce_Config.h +++ b/juce_Config.h @@ -266,13 +266,6 @@ #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1 #endif -/** JUCE_STRINGS_ARE_UNICODE: If this macro is set, the Juce String class will use - unicode as its internal representation. If disabled, it'll use ANSI. -*/ -#ifndef JUCE_STRINGS_ARE_UNICODE - #define JUCE_STRINGS_ARE_UNICODE 1 -#endif - //============================================================================= // If only building the core classes, we can explicitly turn off some features to avoid including them: #if JUCE_ONLY_BUILD_CORE_LIBRARY diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 8c61faf190..3d3912a60f 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -283,10 +283,6 @@ #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1 #endif -#ifndef JUCE_STRINGS_ARE_UNICODE - #define JUCE_STRINGS_ARE_UNICODE 1 -#endif - // If only building the core classes, we can explicitly turn off some features to avoid including them: #if JUCE_ONLY_BUILD_CORE_LIBRARY #undef JUCE_QUICKTIME @@ -1376,7 +1372,9 @@ void juce_initialiseStrings(); const String SystemStats::getJUCEVersion() throw() { - return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION); + return "JUCE v" + String (JUCE_MAJOR_VERSION) + + "." + String (JUCE_MINOR_VERSION) + + "." + String (JUCE_BUILDNUMBER); } static bool juceInitialisedNonGUI = false; @@ -3711,11 +3709,11 @@ void var::writeToStream (OutputStream& output) const case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break; case stringType: { - const int len = value.stringValue->copyToUTF8 (0); + const int len = value.stringValue->getNumBytesAsUTF8() + 1; output.writeCompressedInt (len + 1); output.writeByte (5); HeapBlock temp (len); - value.stringValue->copyToUTF8 (temp); + value.stringValue->copyToUTF8 (temp, len); output.write (temp, len); break; } @@ -3741,7 +3739,7 @@ const var var::readFromStream (InputStream& input) { MemoryBlock mb; input.readIntoMemoryBlock (mb, numBytes - 1); - return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize())); + return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize())); } default: input.skipNextBytes (numBytes - 1); break; @@ -5267,7 +5265,7 @@ double InputStream::readDoubleBigEndian() const String InputStream::readString() { MemoryBlock buffer (256); - uint8* data = (uint8*) buffer.getData(); + char* data = (char*) buffer.getData(); size_t i = 0; while ((data[i] = readByte()) != 0) @@ -5275,7 +5273,7 @@ const String InputStream::readString() if (++i >= buffer.getSize()) { buffer.setSize (buffer.getSize() + 512); - data = (uint8*) buffer.getData(); + data = (char*) buffer.getData(); } } @@ -5285,7 +5283,7 @@ const String InputStream::readString() const String InputStream::readNextLine() { MemoryBlock buffer (256); - uint8* data = (uint8*) buffer.getData(); + char* data = (char*) buffer.getData(); size_t i = 0; while ((data[i] = readByte()) != 0) @@ -5306,7 +5304,7 @@ const String InputStream::readNextLine() if (++i >= buffer.getSize()) { buffer.setSize (buffer.getSize() + 512); - data = (uint8*) buffer.getData(); + data = (char*) buffer.getData(); } } @@ -5524,11 +5522,10 @@ void OutputStream::writeDoubleBigEndian (double value) void OutputStream::writeString (const String& text) { - const int numBytes = text.copyToUTF8 (0); + const int numBytes = text.getNumBytesAsUTF8() + 1; HeapBlock temp (numBytes); - - text.copyToUTF8 (temp); - write (temp, numBytes); // (numBytes includes the terminating null). + text.copyToUTF8 (temp, numBytes); + write (temp, numBytes); } void OutputStream::printf (const char* pf, ...) @@ -5563,14 +5560,14 @@ void OutputStream::printf (const char* pf, ...) OutputStream& OutputStream::operator<< (const int number) { const String s (number); - write ((const char*) s, s.length()); + write (s.toUTF8(), s.getNumBytesAsUTF8()); return *this; } OutputStream& OutputStream::operator<< (const double number) { const String s (number); - write ((const char*) s, s.length()); + write (s.toUTF8(), s.getNumBytesAsUTF8()); return *this; } @@ -5586,18 +5583,9 @@ OutputStream& OutputStream::operator<< (const char* const text) return *this; } -OutputStream& OutputStream::operator<< (const juce_wchar* const text) -{ - const String s (text); - write ((const char*) s, s.length()); - return *this; -} - OutputStream& OutputStream::operator<< (const String& text) { - write ((const char*) text, - text.length()); - + write (text.toUTF8(), text.getNumBytesAsUTF8()); return *this; } @@ -5624,7 +5612,7 @@ void OutputStream::writeText (const String& text, } else { - const char* src = (const char*) text; + const char* src = text.toUTF8(); const char* t = src; for (;;) @@ -5940,10 +5928,9 @@ static const String parseAbsolutePath (String path) else { // expand a name of type "~dave/abc" - const String userName (path.substring (1) - .upToFirstOccurrenceOf (T("/"), false, false)); + const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false)); - struct passwd* const pw = getpwnam (userName); + struct passwd* const pw = getpwnam (userName.toUTF8()); if (pw != 0) { String home (homeDir); @@ -7566,7 +7553,7 @@ static bool connectSocket (int volatile& handle, const int portNumber, const int timeOutMillisecs) throw() { - struct hostent* const hostEnt = gethostbyname (hostName); + struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); if (hostEnt == 0) return false; @@ -8659,8 +8646,7 @@ const String BufferedInputStream::readString() if (src[i] == 0) { position += i + 1; - - return String::fromUTF8 ((const uint8*) src, i); + return String::fromUTF8 (src, i); } } } @@ -9406,7 +9392,7 @@ void ZipFile::init() break; ZipEntryInfo* const zei = new ZipEntryInfo(); - zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen); + zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen); const int time = ByteOrder::littleEndianShort (buffer + 12); const int date = ByteOrder::littleEndianShort (buffer + 14); @@ -9602,6 +9588,31 @@ int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int return wcsncmp (s1, s2, maxChars); } +int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw() +{ + jassert (s1 != 0 && s2 != 0); + + for (;;) + { + const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2); + + if (diff != 0) + return diff; + else if (*s1 == 0) + break; + + ++s1; + ++s2; + } + + return 0; +} + +int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw() +{ + return -compare (s2, s1); +} + int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw() { jassert (s1 != 0 && s2 != 0); @@ -9971,7 +9982,7 @@ double juce_atof (const CharType* const original) throw() } if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') - return atof (String (original)); // Let the c library deal with NAN and INF + return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF for (;;) { @@ -10221,14 +10232,14 @@ bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw() return iswalnum (character) != 0; } -int CharacterFunctions::getHexDigitValue (const tchar digit) throw() +int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw() { - if (digit >= T('0') && digit <= T('9')) - return digit - T('0'); - else if (digit >= T('a') && digit <= T('f')) - return digit - (T('a') - 10); - else if (digit >= T('A') && digit <= T('F')) - return digit - (T('A') - 10); + if (digit >= '0' && digit <= '9') + return digit - '0'; + else if (digit >= 'a' && digit <= 'f') + return digit - ('a' - 10); + else if (digit >= 'A' && digit <= 'F') + return digit - ('A' - 10); return -1; } @@ -10414,6 +10425,10 @@ BEGIN_JUCE_NAMESPACE #pragma warning (pop) #endif +#if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE + #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default." +#endif + static const char* const emptyCharString = "\0\0\0\0JUCE"; static const int safeEmptyStringRefCount = 0x3fffffff; String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } }; @@ -10421,7 +10436,7 @@ static tchar decimalPoint = T('.'); void juce_initialiseStrings() { - decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0]; + decimalPoint = String::fromUTF8 (localeconv()->decimal_point) [0]; } void String::createInternal (const int numChars) throw() @@ -10538,11 +10553,7 @@ String::String (const char* const t) throw() const int len = CharacterFunctions::length (t); createInternal (len); -#if JUCE_STRINGS_ARE_UNICODE CharacterFunctions::copy (text->text, t, len + 1); -#else - memcpy (text->text, t, len + 1); -#endif } else { @@ -10555,17 +10566,9 @@ String::String (const juce_wchar* const t) throw() { if (t != 0 && *t != 0) { -#if JUCE_STRINGS_ARE_UNICODE const int len = CharacterFunctions::length (t); createInternal (len); - memcpy (text->text, t, (len + 1) * sizeof (tchar)); -#else - const int len = CharacterFunctions::bytesRequiredForCopy (t); - createInternal (len); - - CharacterFunctions::copy (text->text, t, len + 1); -#endif } else { @@ -10585,13 +10588,7 @@ String::String (const char* const t, if (i > 0) { createInternal (i); - -#if JUCE_STRINGS_ARE_UNICODE CharacterFunctions::copy (text->text, t, i); -#else - memcpy (text->text, t, i); -#endif - text->text [i] = 0; } else @@ -10612,12 +10609,7 @@ String::String (const juce_wchar* const t, if (i > 0) { createInternal (i); - -#if JUCE_STRINGS_ARE_UNICODE memcpy (text->text, t, i * sizeof (tchar)); -#else - CharacterFunctions::copy (text->text, t, i); -#endif text->text [i] = 0; } else @@ -10627,7 +10619,7 @@ String::String (const juce_wchar* const t, } } -const String String::charToString (const tchar character) throw() +const String String::charToString (const juce_wchar character) throw() { tchar temp[2]; temp[0] = character; @@ -10636,117 +10628,123 @@ const String String::charToString (const tchar character) throw() return String (temp); } -// pass in a pointer to the END of a buffer.. -static tchar* int64ToCharString (tchar* t, const int64 n) throw() +namespace IntToCharConverters { - *--t = 0; - int64 v = (n >= 0) ? n : -n; - - do + // pass in a pointer to the END of a buffer.. + static tchar* int64ToString (tchar* t, const int64 n) throw() { - *--t = (tchar) (T('0') + (int) (v % 10)); - v /= 10; + *--t = 0; + int64 v = (n >= 0) ? n : -n; - } while (v > 0); + do + { + *--t = (tchar) (T('0') + (int) (v % 10)); + v /= 10; - if (n < 0) - *--t = T('-'); + } while (v > 0); - return t; -} + if (n < 0) + *--t = T('-'); -static tchar* intToCharString (tchar* t, const int n) throw() -{ - if (n == (int) 0x80000000) // (would cause an overflow) - return int64ToCharString (t, n); + return t; + } - *--t = 0; - int v = abs (n); - - do + static tchar* uint64ToString (tchar* t, int64 v) throw() { - *--t = (tchar) (T('0') + (v % 10)); - v /= 10; + *--t = 0; - } while (v > 0); + do + { + *--t = (tchar) (T('0') + (int) (v % 10)); + v /= 10; - if (n < 0) - *--t = T('-'); + } while (v > 0); - return t; -} + return t; + } -static tchar* uintToCharString (tchar* t, unsigned int v) throw() -{ - *--t = 0; - - do + static tchar* intToString (tchar* t, const int n) throw() { - *--t = (tchar) (T('0') + (v % 10)); - v /= 10; + if (n == (int) 0x80000000) // (would cause an overflow) + return int64ToString (t, n); - } while (v > 0); + *--t = 0; + int v = abs (n); - return t; + do + { + *--t = (tchar) (T('0') + (v % 10)); + v /= 10; + + } while (v > 0); + + if (n < 0) + *--t = T('-'); + + return t; + } + + static tchar* uintToString (tchar* t, unsigned int v) throw() + { + *--t = 0; + + do + { + *--t = (tchar) (T('0') + (v % 10)); + v /= 10; + + } while (v > 0); + + return t; + } } String::String (const int number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (intToCharString (end, number), end); + createInternal (IntToCharConverters::intToString (end, number), end); } String::String (const unsigned int number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (uintToCharString (end, number), end); + createInternal (IntToCharConverters::uintToString (end, number), end); } String::String (const short number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (intToCharString (end, (int) number), end); + createInternal (IntToCharConverters::intToString (end, (int) number), end); } String::String (const unsigned short number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (uintToCharString (end, (unsigned int) number), end); + createInternal (IntToCharConverters::uintToString (end, (unsigned int) number), end); } String::String (const int64 number) throw() { tchar buffer [32]; - tchar* const end = buffer + 32; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (int64ToCharString (end, number), end); + createInternal (IntToCharConverters::int64ToString (end, number), end); } String::String (const uint64 number) throw() { tchar buffer [32]; - tchar* const end = buffer + 32; - tchar* t = end; + tchar* const end = buffer + numElementsInArray (buffer); - *--t = 0; - int64 v = number; - - do - { - *--t = (tchar) (T('0') + (int) (v % 10)); - v /= 10; - - } while (v > 0); - - createInternal (t, end); + createInternal (IntToCharConverters::uint64ToString (end, number), end); } // a double-to-string routine that actually uses the number of dec. places you asked for @@ -10836,88 +10834,6 @@ void String::preallocateStorage (const size_t numChars) throw() } } -#if JUCE_STRINGS_ARE_UNICODE -String::operator const char*() const throw() -{ - if (isEmpty()) - { - return (const char*) emptyCharString; - } - else - { - String* const mutableThis = const_cast (this); - - mutableThis->dupeInternalIfMultiplyReferenced(); - int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1; - mutableThis->text = (InternalRefCountedStringHolder*) - juce_realloc (text, sizeof (InternalRefCountedStringHolder) - + (len * sizeof (juce_wchar) + len)); - char* otherCopy = (char*) (text->text + len); - --len; - - CharacterFunctions::copy (otherCopy, text->text, len); - otherCopy [len] = 0; - return otherCopy; - } -} - -#else - -String::operator const juce_wchar*() const throw() -{ - if (isEmpty()) - { - return (const juce_wchar*) emptyCharString; - } - else - { - String* const mutableThis = const_cast (this); - - mutableThis->dupeInternalIfMultiplyReferenced(); - int len = CharacterFunctions::length (text->text) + 1; - mutableThis->text = (InternalRefCountedStringHolder*) - juce_realloc (text, sizeof (InternalRefCountedStringHolder) - + (len * sizeof (juce_wchar) + len)); - - juce_wchar* otherCopy = (juce_wchar*) (text->text + len); - --len; - - CharacterFunctions::copy (otherCopy, text->text, len); - otherCopy [len] = 0; - return otherCopy; - } -} - -#endif - -void String::copyToBuffer (char* const destBuffer, - const int bufferSizeBytes) const throw() -{ -#if JUCE_STRINGS_ARE_UNICODE - const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text)); - CharacterFunctions::copy (destBuffer, text->text, len); -#else - const int len = jmin (bufferSizeBytes, length()); - memcpy (destBuffer, text->text, len * sizeof (tchar)); -#endif - - destBuffer [len] = 0; -} - -void String::copyToBuffer (juce_wchar* const destBuffer, - const int maxCharsToCopy) const throw() -{ - const int len = jmin (maxCharsToCopy, length()); - -#if JUCE_STRINGS_ARE_UNICODE - memcpy (destBuffer, text->text, len * sizeof (juce_wchar)); -#else - CharacterFunctions::copy (destBuffer, text->text, len); -#endif - - destBuffer [len] = 0; -} - int String::length() const throw() { return CharacterFunctions::length (text->text); @@ -10945,12 +10861,6 @@ int64 String::hashCode64() const throw() return result; } -const String& String::operator= (const tchar* const otherText) throw() -{ - operator= (String (otherText)); - return *this; -} - const String& String::operator= (const String& other) throw() { if (this != &other) @@ -10968,16 +10878,54 @@ const String& String::operator= (const String& other) throw() return *this; } -bool String::operator== (const String& other) const throw() +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const String& string2) throw() { - return text == other.text - || CharacterFunctions::compare (text->text, other.text->text) == 0; + return string1.compare (string2) == 0; } -bool String::operator== (const tchar* const t) const throw() +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const char* string2) throw() { - return t != 0 ? CharacterFunctions::compare (text->text, t) == 0 - : isEmpty(); + return string1.compare (string2) == 0; +} + +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const juce_wchar* string2) throw() +{ + return string1.compare (string2) == 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const char* string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const juce_wchar* string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator> (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) > 0; +} + +bool JUCE_PUBLIC_FUNCTION operator< (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) < 0; +} + +bool JUCE_PUBLIC_FUNCTION operator>= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) >= 0; +} + +bool JUCE_PUBLIC_FUNCTION operator<= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) <= 0; } bool String::equalsIgnoreCase (const tchar* t) const throw() @@ -10992,132 +10940,40 @@ bool String::equalsIgnoreCase (const String& other) const throw() || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0; } -bool String::operator!= (const String& other) const throw() +int String::compare (const String& other) const throw() { - return text != other.text - && CharacterFunctions::compare (text->text, other.text->text) != 0; + return (text == other.text) ? 0 : CharacterFunctions::compare (text->text, other.text->text); } -bool String::operator!= (const tchar* const t) const throw() +int String::compare (const char* other) const throw() { - return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0) - : isNotEmpty(); + return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other); } -bool String::operator> (const String& other) const throw() +int String::compare (const juce_wchar* other) const throw() { - return compare (other) > 0; + return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other); } -bool String::operator< (const tchar* const other) const throw() +int String::compareIgnoreCase (const String& other) const throw() { - return compare (other) < 0; + return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text->text, other.text->text); } -bool String::operator>= (const String& other) const throw() +int String::compareLexicographically (const String& other) const throw() { - return compare (other) >= 0; -} - -bool String::operator<= (const tchar* const other) const throw() -{ - return compare (other) <= 0; -} - -int String::compare (const tchar* const other) const throw() -{ - return other != 0 ? CharacterFunctions::compare (text->text, other) - : isEmpty(); -} - -int String::compareIgnoreCase (const tchar* const other) const throw() -{ - return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other) - : isEmpty(); -} - -int String::compareLexicographically (const tchar* other) const throw() -{ - if (other == 0) - return isEmpty(); - const tchar* s1 = text->text; while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1)) ++s1; - while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other)) - ++other; + const tchar* s2 = other.text->text; + while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2)) + ++s2; - return CharacterFunctions::compareIgnoreCase (s1, other); + return CharacterFunctions::compareIgnoreCase (s1, s2); } -const String String::operator+ (const String& other) const throw() -{ - if (*(other.text->text) == 0) - return *this; - - if (isEmpty()) - return other; - - const int len = CharacterFunctions::length (text->text); - const int otherLen = CharacterFunctions::length (other.text->text); - - String result (len + otherLen, (int) 0); - memcpy (result.text->text, text->text, len * sizeof (tchar)); - memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar)); - result.text->text [len + otherLen] = 0; - - return result; -} - -const String String::operator+ (const tchar* const textToAppend) const throw() -{ - if (textToAppend == 0 || *textToAppend == 0) - return *this; - - const int len = CharacterFunctions::length (text->text); - const int otherLen = CharacterFunctions::length (textToAppend); - - String result (len + otherLen, (int) 0); - memcpy (result.text->text, text->text, len * sizeof (tchar)); - memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar)); - result.text->text [len + otherLen] = 0; - - return result; -} - -const String String::operator+ (const tchar characterToAppend) const throw() -{ - if (characterToAppend == 0) - return *this; - - const int len = CharacterFunctions::length (text->text); - String result ((int) (len + 1), (int) 0); - - memcpy (result.text->text, text->text, len * sizeof (tchar)); - result.text->text[len] = characterToAppend; - result.text->text[len + 1] = 0; - - return result; -} - -const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, - const String& string2) throw() -{ - String s (string1); - s += string2; - return s; -} - -const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, - const String& string2) throw() -{ - String s (string1); - s += string2; - return s; -} - -const String& String::operator+= (const tchar* const t) throw() +String& String::operator+= (const tchar* const t) { if (t != 0) appendInternal (t, CharacterFunctions::length (t)); @@ -11125,49 +10981,47 @@ const String& String::operator+= (const tchar* const t) throw() return *this; } -const String& String::operator+= (const String& other) throw() +String& String::operator+= (const String& other) { if (isEmpty()) operator= (other); else - appendInternal (other.text->text, - CharacterFunctions::length (other.text->text)); + appendInternal (other.text->text, other.length()); return *this; } -const String& String::operator+= (const char ch) throw() +String& String::operator+= (const char ch) { - char asString[2]; - asString[0] = ch; - asString[1] = 0; - -#if JUCE_STRINGS_ARE_UNICODE - operator+= (String (asString)); -#else - appendInternal (asString, 1); -#endif - - return *this; + const tchar asString[] = { (tchar) ch, 0 }; + return operator+= ((const tchar*) asString); } -const String& String::operator+= (const juce_wchar ch) throw() +String& String::operator+= (const juce_wchar ch) { - juce_wchar asString[2]; - asString[0] = ch; - asString[1] = 0; - -#if JUCE_STRINGS_ARE_UNICODE - appendInternal (asString, 1); -#else - operator+= (String (asString)); -#endif + const tchar asString[] = { (tchar) ch, 0 }; + return operator+= ((const tchar*) asString); +} +String& String::operator+= (const int number) +{ + tchar buffer [16]; + tchar* const end = buffer + numElementsInArray (buffer); + tchar* const start = IntToCharConverters::intToString (end, number); + appendInternal (start, end - start); return *this; } -void String::append (const tchar* const other, - const int howMany) throw() +String& String::operator+= (const unsigned int number) +{ + tchar buffer [16]; + tchar* const end = buffer + numElementsInArray (buffer); + tchar* const start = IntToCharConverters::uintToString (end, number); + appendInternal (start, end - start); + return *this; +} + +void String::append (const tchar* const other, const int howMany) { if (howMany > 0) { @@ -11180,94 +11034,111 @@ void String::append (const tchar* const other, } } -String& String::operator<< (const int number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = intToCharString (end, number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + String s (string1); + return s += string2; } -String& String::operator<< (const unsigned int number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = uintToCharString (end, number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + String s (string1); + return s += string2; } -String& String::operator<< (const short number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const char string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = intToCharString (end, (int) number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + return String::charToString (string1) + string2; } -String& String::operator<< (const long number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar string1, const String& string2) { - return operator<< ((int) number); + return String::charToString (string1) + string2; } -String& String::operator<< (const unsigned long number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const String& string2) { - return operator<< ((unsigned int) number); + return string1 += string2; } -String& String::operator<< (const double number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char* const string2) { - operator+= (String (number)); - return *this; + return string1 += string2; } -String& String::operator<< (const float number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar* const string2) { - operator+= (String (number)); - return *this; + return string1 += string2; } -String& String::operator<< (const char character) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char string2) { - operator+= (character); - return *this; + return string1 += string2; } -String& String::operator<< (const juce_wchar character) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar string2) { - operator+= (character); - return *this; + return string1 += string2; } -String& String::operator<< (const char* const t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char characterToAppend) { -#if JUCE_STRINGS_ARE_UNICODE - operator+= (String (t)); -#else - operator+= (t); -#endif - return *this; + return string1 += characterToAppend; } -String& String::operator<< (const juce_wchar* const t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar characterToAppend) { -#if JUCE_STRINGS_ARE_UNICODE - operator+= (t); -#else - operator+= (String (t)); -#endif - return *this; + return string1 += characterToAppend; } -String& String::operator<< (const String& t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char* const string2) { - operator+= (t); - return *this; + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar* const string2) +{ + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const String& string2) +{ + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const short number) +{ + return string1 += (int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const int number) +{ + return string1 += number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned int number) +{ + return string1 += number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const long number) +{ + return string1 += (int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned long number) +{ + return string1 += (unsigned int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const float number) +{ + return string1 += String (number); +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const double number) +{ + return string1 += String (number); } int String::indexOfChar (const tchar character) const throw() @@ -11853,7 +11724,7 @@ const String String::toLowerCase() const throw() return result; } -tchar& String::operator[] (const int index) throw() +juce_wchar& String::operator[] (const int index) throw() { jassert (((unsigned int) index) <= (unsigned int) length()); @@ -11862,9 +11733,9 @@ tchar& String::operator[] (const int index) throw() return text->text [index]; } -tchar String::getLastCharacter() const throw() +juce_wchar String::getLastCharacter() const throw() { - return (isEmpty()) ? ((tchar) 0) + return (isEmpty()) ? ((juce_wchar) 0) : text->text [CharacterFunctions::length (text->text) - 1]; } @@ -12402,11 +12273,11 @@ const String String::createStringFromData (const void* const data_, } else { - return String::fromUTF8 ((const uint8*) data, size); + return String::fromUTF8 (data, size); } } -const char* String::toUTF8() const throw() +const char* String::toUTF8() const { if (isEmpty()) { @@ -12419,24 +12290,23 @@ const char* String::toUTF8() const throw() mutableThis->dupeInternalIfMultiplyReferenced(); const int currentLen = CharacterFunctions::length (text->text) + 1; - const int utf8BytesNeeded = copyToUTF8 (0); + const int utf8BytesNeeded = getNumBytesAsUTF8() + 1; mutableThis->text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder) + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded)); char* const otherCopy = (char*) (text->text + currentLen); - copyToUTF8 ((uint8*) otherCopy); + copyToUTF8 (otherCopy, std::numeric_limits::max()); return otherCopy; } } -int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw() +int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw() { jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied! -#if JUCE_STRINGS_ARE_UNICODE int num = 0, index = 0; for (;;) @@ -12506,18 +12376,46 @@ int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const } return num; - -#else - const int numBytes = jmin (maxBufferSizeBytes, length() + 1); - - if (buffer != 0) - copyToBuffer ((char*) buffer, maxBufferSizeBytes); - - return numBytes; -#endif } -const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw() +int String::getNumBytesAsUTF8() const throw() +{ + int num = 0; + const juce_wchar* t = text->text; + + for (;;) + { + const uint32 c = (uint32) *t; + + if (c >= 0x80) + { + ++num; + if (c >= 0x800) + { + ++num; + if (c >= 0x10000) + { + ++num; + if (c >= 0x200000) + { + ++num; + if (c >= 0x4000000) + ++num; + } + } + } + } + else if (c == 0) + break; + + ++num; + ++t; + } + + return num; +} + +const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) { if (buffer == 0) return empty; @@ -12531,16 +12429,16 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t break; String result ((int) numBytes + 1, 0); - tchar* dest = result.text->text; + juce_wchar* dest = result.text->text; size_t i = 0; while (i < numBytes) { - const uint8 c = buffer [i++]; + const char c = buffer [i++]; - if ((c & 0x80) != 0) + if (c < 0) { - int mask = 0x7f; + unsigned int mask = 0x7f; int bit = 0x40; int numExtraValues = 0; @@ -12551,11 +12449,11 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t ++numExtraValues; } - int n = (c & mask); + int n = (mask & (unsigned char) c); while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes) { - const uint8 nextByte = buffer[i]; + const char nextByte = buffer[i]; if ((nextByte & 0xc0) != 0x80) break; @@ -12565,11 +12463,11 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t ++i; } - *dest++ = (tchar) n; + *dest++ = (juce_wchar) n; } else { - *dest++ = (tchar) c; + *dest++ = (juce_wchar) c; } } @@ -12577,6 +12475,52 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t return result; } +const char* String::toCString() const +{ + if (isEmpty()) + { + return (const char*) emptyCharString; + } + else + { + String* const mutableThis = const_cast (this); + + mutableThis->dupeInternalIfMultiplyReferenced(); + int len = length() + 1; + mutableThis->text = (InternalRefCountedStringHolder*) + juce_realloc (text, sizeof (InternalRefCountedStringHolder) + + (len * sizeof (juce_wchar) + len)); + char* otherCopy = (char*) (text->text + len); + --len; + + CharacterFunctions::copy (otherCopy, text->text, len); + otherCopy [len] = 0; + return otherCopy; + } +} + +int String::getNumBytesAsCString() const throw() +{ + return (int) wcstombs (0, text->text, 0); +} + +int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw() +{ + const int numBytes = (int) wcstombs (destBuffer, text->text, maxBufferSizeBytes); + + if (destBuffer != 0 && numBytes >= 0) + destBuffer [numBytes] = 0; + + return numBytes; +} + +void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw() +{ + const int len = jmin (maxCharsToCopy, length()); + memcpy (destBuffer, text->text, len * sizeof (juce_wchar)); + destBuffer [len] = 0; +} + String::Concatenator::Concatenator (String& stringToAppendTo) : result (stringToAppendTo), nextIndex (stringToAppendTo.length()) @@ -12594,7 +12538,7 @@ void String::Concatenator::append (const String& s) if (len > 0) { result.preallocateStorage (nextIndex + len); - s.copyToBuffer (const_cast ((const tchar*) result) + nextIndex, len); + s.copyToUnicode (((juce_wchar*) result) + nextIndex, len); nextIndex += len; } } @@ -12871,7 +12815,7 @@ const String StringArray::joinIntoString (const String& separator, int start, in String result; result.preallocateStorage (charsNeeded); - tchar* dest = (tchar*) (const tchar*) result; + juce_wchar* dest = (juce_wchar*) result; while (start < last) { @@ -12880,13 +12824,13 @@ const String StringArray::joinIntoString (const String& separator, int start, in if (len > 0) { - s.copyToBuffer (dest, len); + s.copyToUnicode (dest, len); dest += len; } if (++start < last && separatorLen > 0) { - separator.copyToBuffer (dest, separatorLen); + separator.copyToUnicode (dest, separatorLen); dest += separatorLen; } } @@ -13282,7 +13226,7 @@ XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentEle } else { - textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize()); + textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize()); } if (! onlyReadOuterDocumentElement) @@ -14293,10 +14237,9 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, if (! isTextElement()) { outputStream.writeByte ('<'); - const int nameLen = tagName.length(); - outputStream.write ((const char*) tagName, nameLen); + outputStream << tagName; - const int attIndent = indentationLevel + nameLen + 1; + const int attIndent = indentationLevel + tagName.length() + 1; int lineLen = 0; const XmlAttributeNode* att = attributes; @@ -14309,13 +14252,13 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, lineLen = 0; } - const int attNameLen = att->name.length(); + const int64 startPos = outputStream.getPosition(); outputStream.writeByte (' '); - outputStream.write ((const char*) (att->name), attNameLen); + outputStream << att->name; outputStream.write ("=\"", 2); escapeIllegalXmlChars (outputStream, att->value, true); outputStream.writeByte ('"'); - lineLen += 4 + attNameLen + att->value.length(); + lineLen += (int) (outputStream.getPosition() - startPos); att = att->next; } @@ -14378,7 +14321,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, } outputStream.write ("= 0) outputStream.write (">\r\n", 3); @@ -17225,15 +17168,14 @@ int JUCEApplication::shutdownAppAndClearUp() } #if JUCE_IPHONE - extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app); + extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app); #endif #if ! JUCE_WINDOWS extern const char* juce_Argv0; #endif -int JUCEApplication::main (int argc, char* argv[], - JUCEApplication* const newApp) +int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp) { #if ! JUCE_WINDOWS juce_Argv0 = argv[0]; @@ -17250,7 +17192,7 @@ int JUCEApplication::main (int argc, char* argv[], String cmd; for (int i = 1; i < argc; ++i) - cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' '); + cmd << argv[i] << ' '; return JUCEApplication::main (cmd, newApp); #endif @@ -21685,17 +21627,17 @@ const StringPairArray WavAudioFormat::createBWAVMetadata (const String& descript struct BWAVChunk { - uint8 description [256]; - uint8 originator [32]; - uint8 originatorRef [32]; - uint8 originationDate [10]; - uint8 originationTime [8]; + char description [256]; + char originator [32]; + char originatorRef [32]; + char originationDate [10]; + char originationTime [8]; uint32 timeRefLow; uint32 timeRefHigh; uint16 version; uint8 umid[64]; uint8 reserved[190]; - uint8 codingHistory[1]; + char codingHistory[1]; void copyTo (StringPairArray& values) const { @@ -21715,7 +21657,7 @@ struct BWAVChunk static MemoryBlock createFrom (const StringPairArray& values) { - const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1; + const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8(); MemoryBlock data ((sizeNeeded + 3) & ~3); data.fillWith (0); @@ -21733,7 +21675,7 @@ struct BWAVChunk b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff)); b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32)); - values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory); + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff); if (b->description[0] != 0 || b->originator[0] != 0 @@ -33587,7 +33529,7 @@ void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw() prog->fxVersion = vst_swap (getVersionNumber()); prog->numParams = vst_swap (numParams); - getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1); + getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1); for (int i = 0; i < numParams; ++i) prog->params[i] = vst_swapFloat (getParameter (i)); @@ -33638,7 +33580,7 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz set->numPrograms = vst_swap (numPrograms); set->chunkSize = vst_swap ((long) chunk.getSize()); - getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1); + getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1); chunk.copyTo (set->chunk, 0, chunk.getSize()); } } @@ -33819,7 +33761,7 @@ static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt3 if (JUCEApplication::getInstance() != 0) hostName = JUCEApplication::getInstance()->getApplicationName(); - hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); + hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); } break; @@ -33917,7 +33859,7 @@ VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, Vs #if JUCE_MAC return (VstIntPtr) (void*) &module->parentDirFSSpec; #else - return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName; + return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8(); #endif case audioMasterGetAutomationState: @@ -34163,7 +34105,7 @@ void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest) dest.setSize (64 + 4 * getNumParameters()); dest.fillWith (0); - getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63); + getCurrentProgramName().copyToCString ((char*) dest.getData(), 63); float* const p = (float*) (((char*) dest.getData()) + 64); for (int i = 0; i < getNumParameters(); ++i) @@ -34212,7 +34154,7 @@ void VSTPluginInstance::changeProgramName (int index, const String& newName) if (index == getCurrentProgram()) { if (getNumPrograms() > 0 && newName != getCurrentProgramName()) - dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f); + dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f); } else { @@ -34800,7 +34742,7 @@ void AudioProcessor::copyXmlToBinary (const XmlElement& xml, JUCE_NAMESPACE::MemoryBlock& destData) { const String xmlString (xml.createDocument (String::empty, true, false)); - const int stringLength = xmlString.length(); + const int stringLength = xmlString.getNumBytesAsUTF8(); destData.setSize (stringLength + 10); @@ -34808,7 +34750,7 @@ void AudioProcessor::copyXmlToBinary (const XmlElement& xml, *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber); *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength); - xmlString.copyToBuffer (d + 8, stringLength); + xmlString.copyToUTF8 (d + 8, stringLength + 1); } XmlElement* AudioProcessor::getXmlFromBinary (const void* data, @@ -34821,8 +34763,8 @@ XmlElement* AudioProcessor::getXmlFromBinary (const void* data, if (stringLength > 0) { - XmlDocument doc (String (((const char*) data) + 8, - jmin ((sizeInBytes - 8), stringLength))); + XmlDocument doc (String::fromUTF8 (((const char*) data) + 8, + jmin ((sizeInBytes - 8), stringLength))); return doc.getDocumentElement(); } @@ -70265,7 +70207,7 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, } } - imageOffset = Point() - clipped; + imageOffset = -clipped; } else { @@ -171902,8 +171844,7 @@ public: vorbis_comment_init (&vc); if (JUCEApplication::getInstance() != 0) - vorbis_comment_add_tag (&vc, "ENCODER", - (char*) (const char*) JUCEApplication::getInstance()->getApplicationName()); + vorbis_comment_add_tag (&vc, "ENCODER", const_cast (JUCEApplication::getInstance()->getApplicationName().toUTF8())); vorbis_analysis_init (&vd, &vi); vorbis_block_init (&vd, &vb); @@ -211759,7 +211700,7 @@ DynamicLibraryLoader::~DynamicLibraryLoader() void* DynamicLibraryLoader::findProcAddress (const String& functionName) { - return (void*) GetProcAddress ((HMODULE) libHandle, functionName); + return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString()); } #endif @@ -212271,7 +212212,7 @@ void juce_setCurrentThreadName (const String& name) } info; info.dwType = 0x1000; - info.szName = name; + info.szName = name.toCString(); info.dwThreadID = GetCurrentThreadId(); info.dwFlags = 0; @@ -212457,8 +212398,7 @@ void PlatformUtilities::freeDynamicLibrary (void* h) void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name) { - return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name) - : 0; + return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0; } InterProcessLock::InterProcessLock (const String& name_) @@ -213806,8 +213746,8 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd { MapiMessage message; zerostruct (message); - message.lpszSubject = (LPSTR) (LPCSTR) emailSubject; - message.lpszNoteText = (LPSTR) (LPCSTR) bodyText; + message.lpszSubject = (LPSTR) emailSubject.toCString(); + message.lpszNoteText = (LPSTR) bodyText.toCString(); MapiRecipDesc recip; zerostruct (recip); @@ -213815,7 +213755,7 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd String targetEmailAddress_ (targetEmailAddress); if (targetEmailAddress_.isEmpty()) targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address) - recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_; + recip.lpszName = (LPSTR) targetEmailAddress_.toCString(); message.nRecipCount = 1; message.lpRecips = &recip; @@ -213829,7 +213769,7 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd for (int i = 0; i < filesToAttach.size(); ++i) { files[i].nPosition = (ULONG) -1; - files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i]; + files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString(); } ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS); @@ -215123,7 +215063,7 @@ public: if (taskBarIcon != 0) { taskBarIcon->uFlags = NIF_TIP; - toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1); + toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1); Shell_NotifyIcon (NIM_MODIFY, taskBarIcon); } } @@ -216796,8 +216736,8 @@ Image* juce_createIconForFile (const File& file) { Image* image = 0; - TCHAR filename [1024]; - file.getFullPathName().copyToBuffer (filename, 1023); + WCHAR filename [1024]; + file.getFullPathName().copyToUnicode (filename, 1023); WORD iconNum = 0; HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(), @@ -217248,7 +217188,7 @@ static HDROP createHDrop (const StringArray& fileNames) throw() for (int i = 0; i < fileNames.size(); ++i) { - fileNames[i].copyToBuffer (fname, 2048); + fileNames[i].copyToUnicode (fname, 2048); fname += fileNames[i].length() + 1; } @@ -217295,7 +217235,7 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text) medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR)); char* d = (char*) GlobalLock (medium.hGlobal); - text.copyToBuffer ((WCHAR*) d, numChars + 1); + text.copyToUnicode ((WCHAR*) d, numChars + 1); format.cfFormat = CF_UNICODETEXT; GlobalUnlock (medium.hGlobal); @@ -217345,7 +217285,7 @@ static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe, lf.lfPitchAndFamily = FF_DONTCARE; const String fontName (lpelfe->elfLogFont.lfFaceName); - fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1); + fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1); HDC dc = CreateCompatibleDC (0); EnumFontFamiliesEx (dc, &lf, @@ -217459,7 +217399,7 @@ public: lfw.lfQuality = PROOF_QUALITY; lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE); lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL; - fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1); + fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1); lfw.lfHeight = size > 0 ? size : -256; HFONT standardSizedFont = CreateFontIndirect (&lfw); @@ -217832,7 +217772,7 @@ void FileChooser::showPlatformDialog (Array& results, } else { - currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable); + currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable); initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName(); } @@ -217914,9 +217854,9 @@ void FileChooser::showPlatformDialog (Array& results, { WCHAR filters [1024]; zeromem (filters, sizeof (filters)); - filter.copyToBuffer (filters, 1024); - filter.copyToBuffer (filters + filter.length() + 1, - 1022 - filter.length()); + filter.copyToUnicode (filters, 1024); + filter.copyToUnicode (filters + filter.length() + 1, + 1022 - filter.length()); OPENFILENAMEW of; zerostruct (of); @@ -218007,8 +217947,8 @@ void SystemClipboard::copyTextToClipboard (const String& text) throw() if (bufH != 0) { - wchar_t* const data = (wchar_t*) GlobalLock (bufH); - text.copyToBuffer (data, len); + WCHAR* const data = (WCHAR*) GlobalLock (bufH); + text.copyToUnicode (data, len); GlobalUnlock (bufH); SetClipboardData (CF_UNICODETEXT, bufH); @@ -224691,38 +224631,30 @@ private: HKEY hk = 0; bool ok = false; - if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS) + if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS) { int index = 0; for (;;) { - char buf [512]; + WCHAR buf [512]; - if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS) + if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS) { if (classId.equalsIgnoreCase (buf)) { HKEY subKey, pathKey; - if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS) { - if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS) { - char pathName [600]; + WCHAR pathName [1024]; DWORD dtype = REG_SZ; DWORD dsize = sizeof (pathName); - if (RegQueryValueExA (pathKey, 0, 0, &dtype, - (LPBYTE) pathName, &dsize) == ERROR_SUCCESS) - { - OFSTRUCT of; - zerostruct (of); - - of.cBytes = sizeof (of); - - ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0); - } + if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS) + ok = File (pathName).exists(); RegCloseKey (pathKey); } @@ -224749,29 +224681,25 @@ private: { HKEY subKey; - if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) { - char buf [256]; + WCHAR buf [256]; + zerostruct (buf); DWORD dtype = REG_SZ; DWORD dsize = sizeof (buf); - zeromem (buf, dsize); - if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) + if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) { if (dsize > 0 && checkClassIsOk (buf)) { - wchar_t classIdStr [130]; - MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128); - - String deviceName; CLSID classId; - - if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK) + if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK) { dtype = REG_SZ; dsize = sizeof (buf); + String deviceName; - if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) + if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) deviceName = buf; else deviceName = keyName; @@ -228516,7 +228444,7 @@ const File File::getCurrentWorkingDirectory() bufferSize += 1024; } - return File (String::fromUTF8 ((const uint8*) cwd)); + return File (String::fromUTF8 (cwd)); } bool File::setAsCurrentWorkingDirectory() const @@ -228674,7 +228602,7 @@ const File juce_getExecutableFile() { Dl_info exeInfo; dladdr ((const void*) juce_getExecutableFile, &exeInfo); - return File (String::fromUTF8 ((const uint8*) exeInfo.dli_fname)); + return File (String::fromUTF8 (exeInfo.dli_fname)); } // if this file doesn't exist, find a parent of it that does.. @@ -228736,7 +228664,7 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, if (getattrlist ((const char*) f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof(attrBuf), 0) == 0) { - return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, + return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, (int) attrBuf.mountPointRef.attr_length); } @@ -229019,7 +228947,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) homeDir = pw->pw_dir; } - return File (String::fromUTF8 ((const uint8*) homeDir)); + return File (String::fromUTF8 (homeDir)); } case userDocumentsDirectory: @@ -229054,7 +228982,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) case invokedExecutableFile: if (juce_Argv0 != 0) - return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + return File (String::fromUTF8 (juce_Argv0)); // deliberate fall-through... case currentExecutableFile: @@ -229077,11 +229005,11 @@ const String File::getVersion() const const File File::getLinkedTarget() const { char buffer [4096]; - size_t numChars = readlink ((const char*) getFullPathName().toUTF8(), + size_t numChars = readlink (getFullPathName().toUTF8(), buffer, sizeof (buffer)); if (numChars > 0 && numChars <= sizeof (buffer)) - return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars)); + return File (String::fromUTF8 (buffer, (int) numChars)); return *this; } @@ -229122,7 +229050,7 @@ struct FindFileStruct if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0) { - result = String::fromUTF8 ((const uint8*) de->d_name); + result = String::fromUTF8 (de->d_name); const String path (parentDir + result); @@ -229324,8 +229252,8 @@ void NamedPipe::close() if (intern->createdPipe) { - unlink (intern->pipeInName); - unlink (intern->pipeOutName); + unlink (intern->pipeInName.toUTF8()); + unlink (intern->pipeOutName.toUTF8()); } delete intern; @@ -229354,8 +229282,8 @@ bool NamedPipe::openInternal (const String& pipeName, const bool createPipe) if (createPipe) { - if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST) - || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST)) + if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST) + || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST)) { delete intern; internal = 0; @@ -229379,9 +229307,9 @@ int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMillisec if (intern->pipeIn == -1) { if (intern->createdPipe) - intern->pipeIn = ::open (intern->pipeInName, O_RDWR); + intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR); else - intern->pipeIn = ::open (intern->pipeOutName, O_RDWR); + intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR); if (intern->pipeIn == -1) { @@ -229425,9 +229353,9 @@ int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOut if (intern->pipeOut == -1) { if (intern->createdPipe) - intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY); else - intern->pipeOut = ::open (intern->pipeInName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY); if (intern->pipeOut == -1) { @@ -229786,7 +229714,7 @@ private: numConsecutiveLFs = 0; } - const String header (String::fromUTF8 ((const uint8*) buffer.getData())); + const String header (String::fromUTF8 ((const char*) buffer.getData())); if (header.startsWithIgnoreCase (T("HTTP/"))) return header.trimEnd(); @@ -230111,7 +230039,7 @@ const String SystemStats::getLogonName() user = pw->pw_name; } - return String::fromUTF8 ((const uint8*) user); + return String::fromUTF8 (user); } const String SystemStats::getFullUserName() @@ -230330,7 +230258,7 @@ void PlatformUtilities::freeDynamicLibrary (void* handle) void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName) { - return dlsym (libraryHandle, (const char*) procedureName); + return dlsym (libraryHandle, procedureName.toCString()); } #endif @@ -230375,7 +230303,7 @@ static String juce_readWindowProperty (Window window, Atom prop, bool deleteAfterReading) { String returnData; - uint8 *clipData; + char* clipData; Atom actualType; int actualFormat; unsigned long numItems, bytesLeft; @@ -230384,7 +230312,7 @@ static String juce_readWindowProperty (Window window, Atom prop, 0L /* offset */, 1000000 /* length (max) */, False, AnyPropertyType /* format */, &actualType, &actualFormat, &numItems, &bytesLeft, - &clipData) == Success) + (unsigned char**) &clipData) == Success) { if (actualType == atom_UTF8_STRING && actualFormat == 8) { @@ -230392,7 +230320,7 @@ static String juce_readWindowProperty (Window window, Atom prop, } else if (actualType == XA_STRING && actualFormat == 8) { - returnData = String ((const char*) clipData, numItems); + returnData = String (clipData, numItems); } if (clipData != 0) @@ -230475,17 +230403,17 @@ void juce_handleSelectionRequest (XSelectionRequestEvent &evt) if (evt.target == XA_STRING) { // format data according to system locale - numDataItems = localClipboardContent.length(); - data.calloc (numDataItems + 2); - localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1); + numDataItems = localClipboardContent.getNumBytesAsCString() + 1; + data.calloc (numDataItems + 1); + localClipboardContent.copyToCString (data, numDataItems); propertyFormat = 8; // bits/item } else if (evt.target == atom_UTF8_STRING) { // translate to utf8 - numDataItems = localClipboardContent.copyToUTF8 (0); - data.calloc (numDataItems + 2); - localClipboardContent.copyToUTF8 (data, numDataItems + 1); + numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1; + data.calloc (numDataItems + 1); + localClipboardContent.copyToUTF8 (data, numDataItems); propertyFormat = 8; // bits/item } else if (evt.target == atom_TARGETS) @@ -230727,12 +230655,8 @@ static int errorHandler (Display* display, XErrorEvent* event) XGetErrorText (display, event->error_code, errorStr, 64); - XGetErrorDatabaseText (display, - "XRequest", - (const char*) String (event->request_code), - "Unknown", - requestStr, - 64); + XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(), + "Unknown", requestStr, 64); DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr)); #endif @@ -230822,9 +230746,9 @@ void MessageManager::doPlatformSpecificInitialisation() // Try to connect to a display String displayName (getenv ("DISPLAY")); if (displayName.isEmpty()) - displayName = T(":0.0"); + displayName = ":0.0"; - display = XOpenDisplay (displayName); + display = XOpenDisplay (displayName.toCString()); if (display == 0) { @@ -231207,10 +231131,8 @@ public: do { - if (FT_New_Face (ftLib, - possible.getFullPathName(), - faceIndex, - &face) == 0) + if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(), + faceIndex, &face) == 0) { if (faceIndex == 0) numFaces = face->num_faces; @@ -231305,7 +231227,7 @@ public: } } - if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace)) + if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace)) { face = lastFace; @@ -232733,7 +232655,7 @@ public: KeySym sym; XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0); - const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1); + const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1); int keyCode = (int) unicodeChar; if (keyCode < 0x20) @@ -233237,7 +233159,7 @@ public: String screenAtom ("_NET_SYSTEM_TRAY_S"); screenAtom << screenNumber; - Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false); + Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false); XGrabServer (display); Window managerWin = XGetSelectionOwner (display, selectionAtom); @@ -233799,10 +233721,10 @@ private: return eventTimeOffset + thisMessageTime; } - static void setWindowTitle (Window xwin, const char* const title) throw() + static void setWindowTitle (Window xwin, const String& title) { XTextProperty nameProperty; - char* strings[] = { (char*) title }; + char* strings[] = { const_cast (title.toUTF8()) }; ScopedXLock xlock; if (XStringListToTextProperty (strings, 1, &nameProperty)) @@ -234886,31 +234808,31 @@ static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, uns } } -static void getDeviceProperties (const String& id, +static void getDeviceProperties (const String& deviceID, unsigned int& minChansOut, unsigned int& maxChansOut, unsigned int& minChansIn, unsigned int& maxChansIn, Array & rates) { - if (id.isEmpty()) + if (deviceID.isEmpty()) return; snd_ctl_t* handle; - if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0) + if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0) { snd_pcm_info_t* info; snd_pcm_info_alloca (&info); snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK); - snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue()); + snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue()); snd_pcm_info_set_subdevice (info, 0); if (snd_ctl_pcm_info (handle, info) >= 0) { snd_pcm_t* pcmHandle; - if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) + if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) { getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut); getDeviceSampleRates (pcmHandle, rates); @@ -234924,7 +234846,7 @@ static void getDeviceProperties (const String& id, if (snd_ctl_pcm_info (handle, info) >= 0) { snd_pcm_t* pcmHandle; - if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) + if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) { getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn); @@ -234942,7 +234864,7 @@ static void getDeviceProperties (const String& id, class ALSADevice { public: - ALSADevice (const String& id, + ALSADevice (const String& deviceID, const bool forInput) : handle (0), bitDepth (16), @@ -234950,7 +234872,7 @@ public: isInput (forInput), sampleFormat (AudioDataConverters::int16LE) { - failed (snd_pcm_open (&handle, id, + failed (snd_pcm_open (&handle, deviceID.toUTF8(), forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC)); } @@ -235664,7 +235586,7 @@ public: if (cardNum < 0) break; - if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0) + if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0) { if (snd_ctl_card_info (handle, info) >= 0) { @@ -235860,7 +235782,7 @@ JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, #if JACK_LOGGING_ENABLED static void jack_Log (const String& s) { - puts (s); + std::cerr << s << std::endl; } static void dumpJackErrorMessage (const jack_status_t status) throw() @@ -235919,9 +235841,9 @@ public: for (int i = 0; i < inputChannels.size(); i++) { String inputName; - inputName << "in_" << (++totalNumberOfInputChannels); + inputName << "in_" << ++totalNumberOfInputChannels; - inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName, + inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)); } @@ -235930,9 +235852,9 @@ public: for (int i = 0; i < outputChannels.size (); i++) { String outputName; - outputName << "out_" << (++totalNumberOfOutputChannels); + outputName << "out_" << ++totalNumberOfOutputChannels; - outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName, + outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)); } @@ -236482,8 +236404,7 @@ static snd_seq_t* createDevice (const bool forInput, : SND_SEQ_OPEN_OUTPUT, 0) == 0) { snd_seq_set_client_name (seqHandle, - (const char*) (forInput ? (deviceNameToOpen + T(" Input")) - : (deviceNameToOpen + T(" Output")))); + (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString()); const int portId = snd_seq_create_simple_port (seqHandle, @@ -236937,7 +236858,7 @@ void FileChooser::showPlatformDialog (Array& results, if (status == 0) { - String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize())); + String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize())); StringArray tokens; if (selectMultipleFiles) @@ -237080,9 +237001,9 @@ BEGIN_JUCE_NAMESPACE #define JUCE_ObjCExtraSuffix 3 #endif -#define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d -#define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d) -#define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix) +#define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e +#define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e) +#define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix) /*** End of inlined file: juce_mac_ObjCSuffix.h ***/ @@ -237093,12 +237014,12 @@ BEGIN_JUCE_NAMESPACE static const String nsStringToJuce (NSString* s) { - return String::fromUTF8 ((uint8*) [s UTF8String]); + return String::fromUTF8 ([s UTF8String]); } static NSString* juceStringToNS (const String& s) { - return [NSString stringWithUTF8String: (const char*) s.toUTF8()]; + return [NSString stringWithUTF8String: s.toUTF8()]; } static const String convertUTF16ToString (const UniChar* utf16) @@ -237117,18 +237038,11 @@ const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString) if (cfString != 0) { -#if JUCE_STRINGS_ARE_UNICODE CFRange range = { 0, CFStringGetLength (cfString) }; HeapBlock u (range.length + 1); CFStringGetCharacters (cfString, range, u); u[range.length] = 0; result = convertUTF16ToString (u); -#else - const int len = CFStringGetLength (cfString); - HeapBlock buffer (len + 1); - CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding()); - result = buffer; -#endif } return result; @@ -237136,7 +237050,6 @@ const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString) CFStringRef PlatformUtilities::juceStringToCFString (const String& s) { -#if JUCE_STRINGS_ARE_UNICODE const int len = s.length(); const juce_wchar* t = (const juce_wchar*) s; HeapBlock temp (len + 2); @@ -237145,12 +237058,6 @@ CFStringRef PlatformUtilities::juceStringToCFString (const String& s) temp[i] = t[i]; return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len); - -#else - return CFStringCreateWithCString (kCFAllocatorDefault, - (const char*) s, - CFStringGetSystemEncoding()); -#endif } const String PlatformUtilities::convertToPrecomposedUnicode (const String& s) @@ -237943,8 +237850,8 @@ void NamedPipe::close() if (intern->createdPipe) { - unlink (intern->pipeInName); - unlink (intern->pipeOutName); + unlink (intern->pipeInName.toUTF8()); + unlink (intern->pipeOutName.toUTF8()); } delete intern; @@ -237973,8 +237880,8 @@ bool NamedPipe::openInternal (const String& pipeName, const bool createPipe) if (createPipe) { - if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST) - || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST)) + if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST) + || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST)) { delete intern; internal = 0; @@ -237998,9 +237905,9 @@ int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMillisec if (intern->pipeIn == -1) { if (intern->createdPipe) - intern->pipeIn = ::open (intern->pipeInName, O_RDWR); + intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR); else - intern->pipeIn = ::open (intern->pipeOutName, O_RDWR); + intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR); if (intern->pipeIn == -1) { @@ -238044,9 +237951,9 @@ int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOut if (intern->pipeOut == -1) { if (intern->createdPipe) - intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY); else - intern->pipeOut = ::open (intern->pipeInName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY); if (intern->pipeOut == -1) { @@ -238323,7 +238230,7 @@ const File File::getCurrentWorkingDirectory() bufferSize += 1024; } - return File (String::fromUTF8 ((const uint8*) cwd)); + return File (String::fromUTF8 (cwd)); } bool File::setAsCurrentWorkingDirectory() const @@ -238481,7 +238388,7 @@ const File juce_getExecutableFile() { Dl_info exeInfo; dladdr ((const void*) juce_getExecutableFile, &exeInfo); - return File (String::fromUTF8 ((const uint8*) exeInfo.dli_fname)); + return File (String::fromUTF8 (exeInfo.dli_fname)); } // if this file doesn't exist, find a parent of it that does.. @@ -238543,7 +238450,7 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, if (getattrlist ((const char*) f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof(attrBuf), 0) == 0) { - return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, + return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, (int) attrBuf.mountPointRef.attr_length); } @@ -238868,7 +238775,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) case invokedExecutableFile: if (juce_Argv0 != 0) - return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + return File (String::fromUTF8 (juce_Argv0)); // deliberate fall-through... case currentExecutableFile: @@ -238889,7 +238796,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) break; } - if (resultPath != 0) + if (resultPath.isNotEmpty()) return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath)); return File::nonexistent; @@ -239050,7 +238957,7 @@ void juce_findFileClose (void* handle) bool juce_launchExecutable (const String& pathAndArguments) { - const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 }; + const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 }; const int cpid = fork(); @@ -239130,15 +239037,13 @@ bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path) const String PlatformUtilities::makePathFromFSRef (FSRef* file) { - uint8 path [2048]; - zeromem (path, sizeof (path)); - - String result; + char path [2048]; + zerostruct (path); if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr) - result = String::fromUTF8 (path); + return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path)); - return PlatformUtilities::convertToPrecomposedUnicode (result); + return String::empty; } #endif @@ -239207,10 +239112,10 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE -int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app) +int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app) { juce_intialisingApp = app; - return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate"); + return UIApplicationMain (argc, const_cast (argv), nil, @"JuceAppStartupDelegate"); } ScopedAutoReleasePool::ScopedAutoReleasePool() @@ -248818,7 +248723,7 @@ END_JUCE_NAMESPACE if ([err length] > 0) { - *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]); + *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]); break; } } @@ -249106,7 +249011,7 @@ const StringArray AudioCDBurner::findAvailableDevices() StringArray s; for (unsigned int i = 0; i < [names count]; ++i) - s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String])); + s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String])); return s; } @@ -250106,7 +250011,7 @@ public: String name; { - uint8 channelName [256]; + char channelName [256]; zerostruct (channelName); UInt32 nameSize = sizeof (channelName); UInt32 channelNum = chanNum + 1; @@ -251104,7 +251009,7 @@ public: if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name))) { - const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name))); + const String nameString (String::fromUTF8 (name, (int) strlen (name))); if (! alreadyLogged) log (T("CoreAudio device: ") + nameString); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index b8d8778083..c493629dac 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -43,8 +43,9 @@ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 51 +#define JUCE_BUILDNUMBER 0 -#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8)) +#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8) + JUCE_BUILDNUMBER) /*** Start of inlined file: juce_TargetPlatform.h ***/ @@ -303,10 +304,6 @@ #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1 #endif -#ifndef JUCE_STRINGS_ARE_UNICODE - #define JUCE_STRINGS_ARE_UNICODE 1 -#endif - // If only building the core classes, we can explicitly turn off some features to avoid including them: #if JUCE_ONLY_BUILD_CORE_LIBRARY #undef JUCE_QUICKTIME @@ -963,19 +960,8 @@ inline void ByteOrder::bigEndian24BitToChars (const int value, char* const destB #ifndef __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__ #define __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__ -#if JUCE_STRINGS_ARE_UNICODE - - #define JUCE_T(stringLiteral) (L##stringLiteral) - typedef juce_wchar tchar; - #define juce_tcharToWideChar(c) (c) - -#else - - #define JUCE_T(stringLiteral) (stringLiteral) - typedef char tchar; - #define juce_tcharToWideChar(c) ((juce_wchar) (unsigned char) (c)) - -#endif +#define JUCE_T(stringLiteral) (L##stringLiteral) +typedef juce_wchar tchar; #if ! JUCE_DONT_DEFINE_MACROS @@ -1001,6 +987,8 @@ public: static int compare (const char* const s1, const char* const s2) throw(); static int compare (const juce_wchar* s1, const juce_wchar* s2) throw(); + static int compare (const juce_wchar* s1, const char* s2) throw(); + static int compare (const char* s1, const juce_wchar* s2) throw(); static int compare (const char* const s1, const char* const s2, const int maxChars) throw(); static int compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw(); @@ -1062,7 +1050,7 @@ public: static bool isLetterOrDigit (const char character) throw(); static bool isLetterOrDigit (const juce_wchar character) throw(); - static int getHexDigitValue (const tchar digit) throw(); + static int getHexDigitValue (const juce_wchar digit) throw(); static int printf (char* const dest, const int maxLength, const char* const format, ...) throw(); static int printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw(); @@ -1092,7 +1080,7 @@ public: String (const juce_wchar* const unicodeText, const size_t maxChars) throw(); - static const String charToString (const tchar character) throw(); + static const String charToString (const juce_wchar character) throw(); ~String() throw(); @@ -1106,37 +1094,17 @@ public: // Assignment and concatenation operators.. - const String& operator= (const tchar* const other) throw(); - const String& operator= (const String& other) throw(); - const String& operator+= (const tchar* const textToAppend) throw(); - const String& operator+= (const String& stringToAppend) throw(); - const String& operator+= (const char characterToAppend) throw(); - const String& operator+= (const juce_wchar characterToAppend) throw(); + String& operator+= (const tchar* const textToAppend); + String& operator+= (const String& stringToAppend); + String& operator+= (const char characterToAppend); + String& operator+= (const juce_wchar characterToAppend); + String& operator+= (const int numberToAppend); + String& operator+= (const unsigned int numberToAppend); void append (const tchar* const textToAppend, - const int maxCharsToTake) throw(); - - const String operator+ (const String& stringToAppend) const throw(); - - const String operator+ (const tchar* const textToAppend) const throw(); - - const String operator+ (const tchar characterToAppend) const throw(); - - String& operator<< (const char n) throw(); - String& operator<< (const juce_wchar n) throw(); - String& operator<< (const char* const text) throw(); - String& operator<< (const juce_wchar* const text) throw(); - String& operator<< (const String& text) throw(); - - String& operator<< (const short number) throw(); - String& operator<< (const int number) throw(); - String& operator<< (const unsigned int number) throw(); - String& operator<< (const long number) throw(); - String& operator<< (const unsigned long number) throw(); - String& operator<< (const float number) throw(); - String& operator<< (const double number) throw(); + const int maxCharsToTake); // Comparison methods.. @@ -1144,26 +1112,18 @@ public: inline bool isNotEmpty() const throw() { return text->text[0] != 0; } - bool operator== (const String& other) const throw(); - bool operator== (const tchar* const other) const throw(); - - bool operator!= (const String& other) const throw(); - bool operator!= (const tchar* const other) const throw(); - bool equalsIgnoreCase (const String& other) const throw(); bool equalsIgnoreCase (const tchar* const other) const throw(); - bool operator> (const String& other) const throw(); - bool operator< (const tchar* const other) const throw(); + int compare (const String& other) const throw(); - bool operator>= (const String& other) const throw(); - bool operator<= (const tchar* const other) const throw(); + int compare (const char* other) const throw(); - int compare (const tchar* const other) const throw(); + int compare (const juce_wchar* other) const throw(); - int compareIgnoreCase (const tchar* const other) const throw(); + int compareIgnoreCase (const String& other) const throw(); - int compareLexicographically (const tchar* const other) const throw(); + int compareLexicographically (const String& other) const throw(); bool startsWith (const tchar* const text) const throw(); @@ -1234,11 +1194,11 @@ public: No checks are made to see if the index is within a valid range, so be careful! */ - inline const tchar& operator[] (const int index) const throw() { jassert (((unsigned int) index) <= (unsigned int) length()); return text->text [index]; } + inline const juce_wchar& operator[] (const int index) const throw() { jassert (((unsigned int) index) <= (unsigned int) length()); return text->text [index]; } - tchar& operator[] (const int index) throw(); + juce_wchar& operator[] (const int index) throw(); - tchar getLastCharacter() const throw(); + juce_wchar getLastCharacter() const throw(); const String substring (int startIndex, int endIndex) const throw(); @@ -1361,30 +1321,25 @@ public: const int size, const int groupSize = 1) throw(); - // Casting to character arrays.. - -#if JUCE_STRINGS_ARE_UNICODE - operator const char*() const throw(); - inline operator const juce_wchar*() const throw() { return text->text; } -#else - inline operator const char*() const throw() { return text->text; } - operator const juce_wchar*() const throw(); -#endif + inline operator juce_wchar*() throw() { return text->text; } - void copyToBuffer (char* const destBuffer, - const int maxCharsToCopy) const throw(); + const char* toUTF8() const; - void copyToBuffer (juce_wchar* const destBuffer, - const int maxCharsToCopy) const throw(); + static const String fromUTF8 (const char* utf8buffer, int bufferSizeBytes = -1); - int copyToUTF8 (uint8* const destBuffer, const int maxBufferSizeBytes = 0x7fffffff) const throw(); + int getNumBytesAsUTF8() const throw(); - const char* toUTF8() const throw(); + int copyToUTF8 (char* destBuffer, const int maxBufferSizeBytes) const throw(); - static const String fromUTF8 (const uint8* const utf8buffer, - int bufferSizeBytes = -1) throw(); + const char* toCString() const; + + int getNumBytesAsCString() const throw(); + + int copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw(); + + void copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw(); void preallocateStorage (const size_t numCharsNeeded) throw(); @@ -1412,12 +1367,7 @@ private: { int refCount; int allocatedNumChars; - -#if JUCE_STRINGS_ARE_UNICODE - wchar_t text[1]; -#else - char text[1]; -#endif + wchar_t text[1]; }; InternalRefCountedStringHolder* text; @@ -1433,11 +1383,47 @@ private: void dupeInternalIfMultiplyReferenced() throw(); }; -const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, - const String& string2) throw(); +const String JUCE_PUBLIC_FUNCTION operator+ (const char* string1, const String& string2); +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* string1, const String& string2); +const String JUCE_PUBLIC_FUNCTION operator+ (char string1, const String& string2); +const String JUCE_PUBLIC_FUNCTION operator+ (juce_wchar string1, const String& string2); -const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, - const String& string2) throw(); +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const String& string2); +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char* string2); +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar* string2); +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, char characterToAppend); +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, juce_wchar characterToAppend); + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char characterToAppend); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar characterToAppend); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char* const string2); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar* const string2); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const String& string2); + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const short number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const int number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned int number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const long number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned long number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const float number); +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const double number); + +template +std::basic_ostream & operator<< (std::basic_ostream & stream, const String& stringToWrite) +{ + return stream << stringToWrite.toUTF8(); +} + +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const String& string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const char* string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const juce_wchar* string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const String& string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const char* string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const juce_wchar* string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator> (const String& string1, const String& string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator< (const String& string1, const String& string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator>= (const String& string1, const String& string2) throw(); +bool JUCE_PUBLIC_FUNCTION operator<= (const String& string1, const String& string2) throw(); #endif // __JUCE_STRING_JUCEHEADER__ /*** End of inlined file: juce_String.h ***/ @@ -2864,8 +2850,6 @@ public: virtual OutputStream& operator<< (const char* const text); - virtual OutputStream& operator<< (const juce_wchar* const text); - virtual OutputStream& operator<< (const String& text); juce_UseDebuggingNewOperator @@ -3355,7 +3339,7 @@ public: { // Two ScopedPointers should never be able to refer to the same object - if // this happens, you must have done something dodgy! - jassert (object != objectToTransferFrom.object); + jassert (object == 0 || object != objectToTransferFrom.object); ObjectType* const oldObject = object; object = objectToTransferFrom.object; @@ -9161,6 +9145,8 @@ public: Point& operator-= (const Point& other) throw() { x -= other.x; y -= other.y; return *this; } + const Point operator-() const throw() { return Point (-x, -y); } + ValueType getDistanceFrom (const Point& other) const throw() { return (ValueType) juce_hypot (x - other.x, y - other.y); } void applyTransform (const AffineTransform& transform) throw() { transform.transformPoint (x, y); } @@ -12900,7 +12886,7 @@ public: // These are used by the START_JUCE_APPLICATION() macro and aren't for public use. static int main (String& commandLine, JUCEApplication* const newApp); - static int main (int argc, char* argv[], JUCEApplication* const newApp); + static int main (int argc, const char* argv[], JUCEApplication* const newApp); static void sendUnhandledException (const std::exception* const e, const char* const sourceFile, @@ -28284,7 +28270,7 @@ END_JUCE_NAMESPACE #define START_JUCE_APPLICATION(AppClass) \ int main (int argc, char* argv[]) \ { \ - return JUCE_NAMESPACE::JUCEApplication::main (argc, argv, new AppClass()); \ + return JUCE_NAMESPACE::JUCEApplication::main (argc, (const char**) argv, new AppClass()); \ } #elif JUCE_WINDOWS diff --git a/src/application/juce_Application.cpp b/src/application/juce_Application.cpp index 2983513a5c..6d959cf426 100644 --- a/src/application/juce_Application.cpp +++ b/src/application/juce_Application.cpp @@ -272,15 +272,14 @@ int JUCEApplication::shutdownAppAndClearUp() } #if JUCE_IPHONE - extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app); + extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app); #endif #if ! JUCE_WINDOWS extern const char* juce_Argv0; #endif -int JUCEApplication::main (int argc, char* argv[], - JUCEApplication* const newApp) +int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp) { #if ! JUCE_WINDOWS juce_Argv0 = argv[0]; @@ -297,7 +296,7 @@ int JUCEApplication::main (int argc, char* argv[], String cmd; for (int i = 1; i < argc; ++i) - cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' '); + cmd << argv[i] << ' '; return JUCEApplication::main (cmd, newApp); #endif diff --git a/src/application/juce_Application.h b/src/application/juce_Application.h index 1f2078db41..05d72d439a 100644 --- a/src/application/juce_Application.h +++ b/src/application/juce_Application.h @@ -265,7 +265,7 @@ public: /** @internal */ static int main (String& commandLine, JUCEApplication* const newApp); /** @internal */ - static int main (int argc, char* argv[], JUCEApplication* const newApp); + static int main (int argc, const char* argv[], JUCEApplication* const newApp); /** @internal */ static void sendUnhandledException (const std::exception* const e, diff --git a/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp b/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp index 4102878b2e..84ec62f021 100644 --- a/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp @@ -280,8 +280,7 @@ public: vorbis_comment_init (&vc); if (JUCEApplication::getInstance() != 0) - vorbis_comment_add_tag (&vc, "ENCODER", - (char*) (const char*) JUCEApplication::getInstance()->getApplicationName()); + vorbis_comment_add_tag (&vc, "ENCODER", const_cast (JUCEApplication::getInstance()->getApplicationName().toUTF8())); vorbis_analysis_init (&vd, &vi); vorbis_block_init (&vd, &vb); diff --git a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp index 50f423372d..055730066d 100644 --- a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp @@ -81,17 +81,17 @@ const StringPairArray WavAudioFormat::createBWAVMetadata (const String& descript struct BWAVChunk { - uint8 description [256]; - uint8 originator [32]; - uint8 originatorRef [32]; - uint8 originationDate [10]; - uint8 originationTime [8]; + char description [256]; + char originator [32]; + char originatorRef [32]; + char originationDate [10]; + char originationTime [8]; uint32 timeRefLow; uint32 timeRefHigh; uint16 version; uint8 umid[64]; uint8 reserved[190]; - uint8 codingHistory[1]; + char codingHistory[1]; void copyTo (StringPairArray& values) const { @@ -111,7 +111,7 @@ struct BWAVChunk static MemoryBlock createFrom (const StringPairArray& values) { - const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1; + const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8(); MemoryBlock data ((sizeNeeded + 3) & ~3); data.fillWith (0); @@ -129,7 +129,7 @@ struct BWAVChunk b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff)); b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32)); - values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory); + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff); if (b->description[0] != 0 || b->originator[0] != 0 diff --git a/src/audio/plugins/formats/juce_VSTPluginFormat.cpp b/src/audio/plugins/formats/juce_VSTPluginFormat.cpp index ab70616189..0744fe31d8 100644 --- a/src/audio/plugins/formats/juce_VSTPluginFormat.cpp +++ b/src/audio/plugins/formats/juce_VSTPluginFormat.cpp @@ -2040,7 +2040,7 @@ void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw() prog->fxVersion = vst_swap (getVersionNumber()); prog->numParams = vst_swap (numParams); - getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1); + getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1); for (int i = 0; i < numParams; ++i) prog->params[i] = vst_swapFloat (getParameter (i)); @@ -2091,7 +2091,7 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz set->numPrograms = vst_swap (numPrograms); set->chunkSize = vst_swap ((long) chunk.getSize()); - getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1); + getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1); chunk.copyTo (set->chunk, 0, chunk.getSize()); } } @@ -2275,7 +2275,7 @@ static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt3 if (JUCEApplication::getInstance() != 0) hostName = JUCEApplication::getInstance()->getApplicationName(); - hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); + hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); } break; @@ -2373,7 +2373,7 @@ VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, Vs #if JUCE_MAC return (VstIntPtr) (void*) &module->parentDirFSSpec; #else - return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName; + return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8(); #endif case audioMasterGetAutomationState: @@ -2621,7 +2621,7 @@ void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest) dest.setSize (64 + 4 * getNumParameters()); dest.fillWith (0); - getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63); + getCurrentProgramName().copyToCString ((char*) dest.getData(), 63); float* const p = (float*) (((char*) dest.getData()) + 64); for (int i = 0; i < getNumParameters(); ++i) @@ -2671,7 +2671,7 @@ void VSTPluginInstance::changeProgramName (int index, const String& newName) if (index == getCurrentProgram()) { if (getNumPrograms() > 0 && newName != getCurrentProgramName()) - dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f); + dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f); } else { diff --git a/src/audio/processors/juce_AudioProcessor.cpp b/src/audio/processors/juce_AudioProcessor.cpp index 7fcc1021a8..a442ca7d22 100644 --- a/src/audio/processors/juce_AudioProcessor.cpp +++ b/src/audio/processors/juce_AudioProcessor.cpp @@ -262,7 +262,7 @@ void AudioProcessor::copyXmlToBinary (const XmlElement& xml, JUCE_NAMESPACE::MemoryBlock& destData) { const String xmlString (xml.createDocument (String::empty, true, false)); - const int stringLength = xmlString.length(); + const int stringLength = xmlString.getNumBytesAsUTF8(); destData.setSize (stringLength + 10); @@ -270,7 +270,7 @@ void AudioProcessor::copyXmlToBinary (const XmlElement& xml, *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber); *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength); - xmlString.copyToBuffer (d + 8, stringLength); + xmlString.copyToUTF8 (d + 8, stringLength + 1); } XmlElement* AudioProcessor::getXmlFromBinary (const void* data, @@ -283,8 +283,8 @@ XmlElement* AudioProcessor::getXmlFromBinary (const void* data, if (stringLength > 0) { - XmlDocument doc (String (((const char*) data) + 8, - jmin ((sizeInBytes - 8), stringLength))); + XmlDocument doc (String::fromUTF8 (((const char*) data) + 8, + jmin ((sizeInBytes - 8), stringLength))); return doc.getDocumentElement(); } diff --git a/src/containers/juce_ScopedPointer.h b/src/containers/juce_ScopedPointer.h index 37b5fa4cf9..9ee1f8ccc6 100644 --- a/src/containers/juce_ScopedPointer.h +++ b/src/containers/juce_ScopedPointer.h @@ -92,7 +92,7 @@ public: { // Two ScopedPointers should never be able to refer to the same object - if // this happens, you must have done something dodgy! - jassert (object != objectToTransferFrom.object); + jassert (object == 0 || object != objectToTransferFrom.object); ObjectType* const oldObject = object; object = objectToTransferFrom.object; diff --git a/src/containers/juce_Variant.cpp b/src/containers/juce_Variant.cpp index ac2b385828..9a3dddb897 100644 --- a/src/containers/juce_Variant.cpp +++ b/src/containers/juce_Variant.cpp @@ -241,11 +241,11 @@ void var::writeToStream (OutputStream& output) const case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break; case stringType: { - const int len = value.stringValue->copyToUTF8 (0); + const int len = value.stringValue->getNumBytesAsUTF8() + 1; output.writeCompressedInt (len + 1); output.writeByte (5); HeapBlock temp (len); - value.stringValue->copyToUTF8 (temp); + value.stringValue->copyToUTF8 (temp, len); output.write (temp, len); break; } @@ -271,7 +271,7 @@ const var var::readFromStream (InputStream& input) { MemoryBlock mb; input.readIntoMemoryBlock (mb, numBytes - 1); - return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize())); + return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize())); } default: input.skipNextBytes (numBytes - 1); break; diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index cac70f6c71..4fd8c25f0b 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,6 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 51 +#define JUCE_BUILDNUMBER 0 /** Current Juce version number. @@ -42,7 +43,7 @@ See also SystemStats::getJUCEVersion() for a string version. */ -#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8)) +#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8) + JUCE_BUILDNUMBER) //============================================================================== diff --git a/src/core/juce_SystemStats.cpp b/src/core/juce_SystemStats.cpp index 7205cbbc61..804975e1ed 100644 --- a/src/core/juce_SystemStats.cpp +++ b/src/core/juce_SystemStats.cpp @@ -43,10 +43,11 @@ void juce_initialiseStrings(); //============================================================================== const String SystemStats::getJUCEVersion() throw() { - return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION); + return "JUCE v" + String (JUCE_MAJOR_VERSION) + + "." + String (JUCE_MINOR_VERSION) + + "." + String (JUCE_BUILDNUMBER); } - //============================================================================== static bool juceInitialisedNonGUI = false; diff --git a/src/gui/components/mouse/juce_DragAndDropContainer.cpp b/src/gui/components/mouse/juce_DragAndDropContainer.cpp index 1fb7e1f87c..1ccf9b9bbf 100644 --- a/src/gui/components/mouse/juce_DragAndDropContainer.cpp +++ b/src/gui/components/mouse/juce_DragAndDropContainer.cpp @@ -390,7 +390,7 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, } } - imageOffset = Point() - clipped; + imageOffset = -clipped; } else { diff --git a/src/gui/graphics/geometry/juce_Point.h b/src/gui/graphics/geometry/juce_Point.h index 317408365e..b9ff8256b2 100644 --- a/src/gui/graphics/geometry/juce_Point.h +++ b/src/gui/graphics/geometry/juce_Point.h @@ -89,6 +89,9 @@ public: /** Subtracts another point's co-ordinates to this one. */ Point& operator-= (const Point& other) throw() { x -= other.x; y -= other.y; return *this; } + /** Returns the inverse of this point. */ + const Point operator-() const throw() { return Point (-x, -y); } + /** Returns the straight-line distance between this point and another one. */ ValueType getDistanceFrom (const Point& other) const throw() { return (ValueType) juce_hypot (x - other.x, y - other.y); } diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 22a9ddbfaa..e6abda4ccf 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -158,10 +158,9 @@ static const String parseAbsolutePath (String path) else { // expand a name of type "~dave/abc" - const String userName (path.substring (1) - .upToFirstOccurrenceOf (T("/"), false, false)); + const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false)); - struct passwd* const pw = getpwnam (userName); + struct passwd* const pw = getpwnam (userName.toUTF8()); if (pw != 0) { String home (homeDir); diff --git a/src/io/files/juce_ZipFile.cpp b/src/io/files/juce_ZipFile.cpp index a6b337efd4..e68e001492 100644 --- a/src/io/files/juce_ZipFile.cpp +++ b/src/io/files/juce_ZipFile.cpp @@ -311,7 +311,7 @@ void ZipFile::init() break; ZipEntryInfo* const zei = new ZipEntryInfo(); - zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen); + zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen); const int time = ByteOrder::littleEndianShort (buffer + 12); const int date = ByteOrder::littleEndianShort (buffer + 14); diff --git a/src/io/network/juce_Socket.cpp b/src/io/network/juce_Socket.cpp index 4266dca9cb..92fae7d29e 100644 --- a/src/io/network/juce_Socket.cpp +++ b/src/io/network/juce_Socket.cpp @@ -243,7 +243,7 @@ static bool connectSocket (int volatile& handle, const int portNumber, const int timeOutMillisecs) throw() { - struct hostent* const hostEnt = gethostbyname (hostName); + struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); if (hostEnt == 0) return false; diff --git a/src/io/streams/juce_BufferedInputStream.cpp b/src/io/streams/juce_BufferedInputStream.cpp index f8e17ff80c..7ce791a90d 100644 --- a/src/io/streams/juce_BufferedInputStream.cpp +++ b/src/io/streams/juce_BufferedInputStream.cpp @@ -171,8 +171,7 @@ const String BufferedInputStream::readString() if (src[i] == 0) { position += i + 1; - - return String::fromUTF8 ((const uint8*) src, i); + return String::fromUTF8 (src, i); } } } diff --git a/src/io/streams/juce_InputStream.cpp b/src/io/streams/juce_InputStream.cpp index 5f3f776c27..9fb85fbd53 100644 --- a/src/io/streams/juce_InputStream.cpp +++ b/src/io/streams/juce_InputStream.cpp @@ -157,7 +157,7 @@ double InputStream::readDoubleBigEndian() const String InputStream::readString() { MemoryBlock buffer (256); - uint8* data = (uint8*) buffer.getData(); + char* data = (char*) buffer.getData(); size_t i = 0; while ((data[i] = readByte()) != 0) @@ -165,7 +165,7 @@ const String InputStream::readString() if (++i >= buffer.getSize()) { buffer.setSize (buffer.getSize() + 512); - data = (uint8*) buffer.getData(); + data = (char*) buffer.getData(); } } @@ -175,7 +175,7 @@ const String InputStream::readString() const String InputStream::readNextLine() { MemoryBlock buffer (256); - uint8* data = (uint8*) buffer.getData(); + char* data = (char*) buffer.getData(); size_t i = 0; while ((data[i] = readByte()) != 0) @@ -196,7 +196,7 @@ const String InputStream::readNextLine() if (++i >= buffer.getSize()) { buffer.setSize (buffer.getSize() + 512); - data = (uint8*) buffer.getData(); + data = (char*) buffer.getData(); } } diff --git a/src/io/streams/juce_OutputStream.cpp b/src/io/streams/juce_OutputStream.cpp index e0e06815b2..7067dee3ec 100644 --- a/src/io/streams/juce_OutputStream.cpp +++ b/src/io/streams/juce_OutputStream.cpp @@ -167,11 +167,10 @@ void OutputStream::writeDoubleBigEndian (double value) void OutputStream::writeString (const String& text) { - const int numBytes = text.copyToUTF8 (0); + const int numBytes = text.getNumBytesAsUTF8() + 1; HeapBlock temp (numBytes); - - text.copyToUTF8 (temp); - write (temp, numBytes); // (numBytes includes the terminating null). + text.copyToUTF8 (temp, numBytes); + write (temp, numBytes); } void OutputStream::printf (const char* pf, ...) @@ -206,14 +205,14 @@ void OutputStream::printf (const char* pf, ...) OutputStream& OutputStream::operator<< (const int number) { const String s (number); - write ((const char*) s, s.length()); + write (s.toUTF8(), s.getNumBytesAsUTF8()); return *this; } OutputStream& OutputStream::operator<< (const double number) { const String s (number); - write ((const char*) s, s.length()); + write (s.toUTF8(), s.getNumBytesAsUTF8()); return *this; } @@ -229,18 +228,9 @@ OutputStream& OutputStream::operator<< (const char* const text) return *this; } -OutputStream& OutputStream::operator<< (const juce_wchar* const text) -{ - const String s (text); - write ((const char*) s, s.length()); - return *this; -} - OutputStream& OutputStream::operator<< (const String& text) { - write ((const char*) text, - text.length()); - + write (text.toUTF8(), text.getNumBytesAsUTF8()); return *this; } @@ -267,7 +257,7 @@ void OutputStream::writeText (const String& text, } else { - const char* src = (const char*) text; + const char* src = text.toUTF8(); const char* t = src; for (;;) diff --git a/src/io/streams/juce_OutputStream.h b/src/io/streams/juce_OutputStream.h index 5b170032cd..42baeb81f5 100644 --- a/src/io/streams/juce_OutputStream.h +++ b/src/io/streams/juce_OutputStream.h @@ -235,14 +235,9 @@ public: /** Writes a null-terminated string to the stream. */ virtual OutputStream& operator<< (const char* const text); - /** Writes a null-terminated unicode text string to the stream, converting it - to 8-bit characters in the default system encoding. */ - virtual OutputStream& operator<< (const juce_wchar* const text); - - /** Writes a string to the stream as 8-bit characters in the default system encoding. */ + /** Writes a null-terminated text string to the stream, converting it to UTF8. */ virtual OutputStream& operator<< (const String& text); - //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/native/common/juce_posix_NamedPipe.cpp b/src/native/common/juce_posix_NamedPipe.cpp index f7ca3b59cc..35299f20b7 100644 --- a/src/native/common/juce_posix_NamedPipe.cpp +++ b/src/native/common/juce_posix_NamedPipe.cpp @@ -74,8 +74,8 @@ void NamedPipe::close() if (intern->createdPipe) { - unlink (intern->pipeInName); - unlink (intern->pipeOutName); + unlink (intern->pipeInName.toUTF8()); + unlink (intern->pipeOutName.toUTF8()); } delete intern; @@ -104,8 +104,8 @@ bool NamedPipe::openInternal (const String& pipeName, const bool createPipe) if (createPipe) { - if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST) - || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST)) + if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST) + || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST)) { delete intern; internal = 0; @@ -129,9 +129,9 @@ int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMillisec if (intern->pipeIn == -1) { if (intern->createdPipe) - intern->pipeIn = ::open (intern->pipeInName, O_RDWR); + intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR); else - intern->pipeIn = ::open (intern->pipeOutName, O_RDWR); + intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR); if (intern->pipeIn == -1) { @@ -175,9 +175,9 @@ int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOut if (intern->pipeOut == -1) { if (intern->createdPipe) - intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY); else - intern->pipeOut = ::open (intern->pipeInName, O_WRONLY); + intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY); if (intern->pipeOut == -1) { diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index adf5a24a72..13b9e94cee 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -178,7 +178,7 @@ const File File::getCurrentWorkingDirectory() bufferSize += 1024; } - return File (String::fromUTF8 ((const uint8*) cwd)); + return File (String::fromUTF8 (cwd)); } bool File::setAsCurrentWorkingDirectory() const @@ -338,7 +338,7 @@ const File juce_getExecutableFile() { Dl_info exeInfo; dladdr ((const void*) juce_getExecutableFile, &exeInfo); - return File (String::fromUTF8 ((const uint8*) exeInfo.dli_fname)); + return File (String::fromUTF8 (exeInfo.dli_fname)); } //============================================================================== @@ -401,7 +401,7 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, if (getattrlist ((const char*) f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof(attrBuf), 0) == 0) { - return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, + return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, (int) attrBuf.mountPointRef.attr_length); } diff --git a/src/native/linux/juce_linux_Audio.cpp b/src/native/linux/juce_linux_Audio.cpp index e00c4d5c80..26bad4fcf8 100644 --- a/src/native/linux/juce_linux_Audio.cpp +++ b/src/native/linux/juce_linux_Audio.cpp @@ -61,31 +61,31 @@ static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, uns } } -static void getDeviceProperties (const String& id, +static void getDeviceProperties (const String& deviceID, unsigned int& minChansOut, unsigned int& maxChansOut, unsigned int& minChansIn, unsigned int& maxChansIn, Array & rates) { - if (id.isEmpty()) + if (deviceID.isEmpty()) return; snd_ctl_t* handle; - if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0) + if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0) { snd_pcm_info_t* info; snd_pcm_info_alloca (&info); snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK); - snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue()); + snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue()); snd_pcm_info_set_subdevice (info, 0); if (snd_ctl_pcm_info (handle, info) >= 0) { snd_pcm_t* pcmHandle; - if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) + if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) { getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut); getDeviceSampleRates (pcmHandle, rates); @@ -99,7 +99,7 @@ static void getDeviceProperties (const String& id, if (snd_ctl_pcm_info (handle, info) >= 0) { snd_pcm_t* pcmHandle; - if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) + if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0) { getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn); @@ -118,7 +118,7 @@ static void getDeviceProperties (const String& id, class ALSADevice { public: - ALSADevice (const String& id, + ALSADevice (const String& deviceID, const bool forInput) : handle (0), bitDepth (16), @@ -126,7 +126,7 @@ public: isInput (forInput), sampleFormat (AudioDataConverters::int16LE) { - failed (snd_pcm_open (&handle, id, + failed (snd_pcm_open (&handle, deviceID.toUTF8(), forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC)); } @@ -861,7 +861,7 @@ public: if (cardNum < 0) break; - if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0) + if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0) { if (snd_ctl_card_info (handle, info) >= 0) { diff --git a/src/native/linux/juce_linux_Clipboard.cpp b/src/native/linux/juce_linux_Clipboard.cpp index 620212b934..9f29993927 100644 --- a/src/native/linux/juce_linux_Clipboard.cpp +++ b/src/native/linux/juce_linux_Clipboard.cpp @@ -60,7 +60,7 @@ static String juce_readWindowProperty (Window window, Atom prop, bool deleteAfterReading) { String returnData; - uint8 *clipData; + char* clipData; Atom actualType; int actualFormat; unsigned long numItems, bytesLeft; @@ -69,7 +69,7 @@ static String juce_readWindowProperty (Window window, Atom prop, 0L /* offset */, 1000000 /* length (max) */, False, AnyPropertyType /* format */, &actualType, &actualFormat, &numItems, &bytesLeft, - &clipData) == Success) + (unsigned char**) &clipData) == Success) { if (actualType == atom_UTF8_STRING && actualFormat == 8) { @@ -77,7 +77,7 @@ static String juce_readWindowProperty (Window window, Atom prop, } else if (actualType == XA_STRING && actualFormat == 8) { - returnData = String ((const char*) clipData, numItems); + returnData = String (clipData, numItems); } if (clipData != 0) @@ -162,17 +162,17 @@ void juce_handleSelectionRequest (XSelectionRequestEvent &evt) if (evt.target == XA_STRING) { // format data according to system locale - numDataItems = localClipboardContent.length(); - data.calloc (numDataItems + 2); - localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1); + numDataItems = localClipboardContent.getNumBytesAsCString() + 1; + data.calloc (numDataItems + 1); + localClipboardContent.copyToCString (data, numDataItems); propertyFormat = 8; // bits/item } else if (evt.target == atom_UTF8_STRING) { // translate to utf8 - numDataItems = localClipboardContent.copyToUTF8 (0); - data.calloc (numDataItems + 2); - localClipboardContent.copyToUTF8 (data, numDataItems + 1); + numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1; + data.calloc (numDataItems + 1); + localClipboardContent.copyToUTF8 (data, numDataItems); propertyFormat = 8; // bits/item } else if (evt.target == atom_TARGETS) diff --git a/src/native/linux/juce_linux_FileChooser.cpp b/src/native/linux/juce_linux_FileChooser.cpp index 7f566d181e..41b2a42d09 100644 --- a/src/native/linux/juce_linux_FileChooser.cpp +++ b/src/native/linux/juce_linux_FileChooser.cpp @@ -81,7 +81,7 @@ void FileChooser::showPlatformDialog (Array& results, if (status == 0) { - String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize())); + String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize())); StringArray tokens; if (selectMultipleFiles) diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index 9440802995..480fa9135f 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -188,7 +188,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) homeDir = pw->pw_dir; } - return File (String::fromUTF8 ((const uint8*) homeDir)); + return File (String::fromUTF8 (homeDir)); } case userDocumentsDirectory: @@ -223,7 +223,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) case invokedExecutableFile: if (juce_Argv0 != 0) - return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + return File (String::fromUTF8 (juce_Argv0)); // deliberate fall-through... case currentExecutableFile: @@ -248,11 +248,11 @@ const String File::getVersion() const const File File::getLinkedTarget() const { char buffer [4096]; - size_t numChars = readlink ((const char*) getFullPathName().toUTF8(), + size_t numChars = readlink (getFullPathName().toUTF8(), buffer, sizeof (buffer)); if (numChars > 0 && numChars <= sizeof (buffer)) - return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars)); + return File (String::fromUTF8 (buffer, (int) numChars)); return *this; } @@ -295,7 +295,7 @@ struct FindFileStruct if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0) { - result = String::fromUTF8 ((const uint8*) de->d_name); + result = String::fromUTF8 (de->d_name); const String path (parentDir + result); diff --git a/src/native/linux/juce_linux_Fonts.cpp b/src/native/linux/juce_linux_Fonts.cpp index ba4a517ea4..cc5dcebc98 100644 --- a/src/native/linux/juce_linux_Fonts.cpp +++ b/src/native/linux/juce_linux_Fonts.cpp @@ -178,10 +178,8 @@ public: do { - if (FT_New_Face (ftLib, - possible.getFullPathName(), - faceIndex, - &face) == 0) + if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(), + faceIndex, &face) == 0) { if (faceIndex == 0) numFaces = face->num_faces; @@ -276,7 +274,7 @@ public: } } - if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace)) + if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace)) { face = lastFace; diff --git a/src/native/linux/juce_linux_JackAudio.cpp b/src/native/linux/juce_linux_JackAudio.cpp index 7b70c959db..d90ff24b08 100644 --- a/src/native/linux/juce_linux_JackAudio.cpp +++ b/src/native/linux/juce_linux_JackAudio.cpp @@ -86,7 +86,7 @@ JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, #if JACK_LOGGING_ENABLED static void jack_Log (const String& s) { - puts (s); + std::cerr << s << std::endl; } static void dumpJackErrorMessage (const jack_status_t status) throw() @@ -148,9 +148,9 @@ public: for (int i = 0; i < inputChannels.size(); i++) { String inputName; - inputName << "in_" << (++totalNumberOfInputChannels); + inputName << "in_" << ++totalNumberOfInputChannels; - inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName, + inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)); } @@ -159,9 +159,9 @@ public: for (int i = 0; i < outputChannels.size (); i++) { String outputName; - outputName << "out_" << (++totalNumberOfOutputChannels); + outputName << "out_" << ++totalNumberOfOutputChannels; - outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName, + outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)); } diff --git a/src/native/linux/juce_linux_Messaging.cpp b/src/native/linux/juce_linux_Messaging.cpp index b2b4eded19..22beb09dda 100644 --- a/src/native/linux/juce_linux_Messaging.cpp +++ b/src/native/linux/juce_linux_Messaging.cpp @@ -183,12 +183,8 @@ static int errorHandler (Display* display, XErrorEvent* event) XGetErrorText (display, event->error_code, errorStr, 64); - XGetErrorDatabaseText (display, - "XRequest", - (const char*) String (event->request_code), - "Unknown", - requestStr, - 64); + XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(), + "Unknown", requestStr, 64); DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr)); #endif @@ -279,9 +275,9 @@ void MessageManager::doPlatformSpecificInitialisation() // Try to connect to a display String displayName (getenv ("DISPLAY")); if (displayName.isEmpty()) - displayName = T(":0.0"); + displayName = ":0.0"; - display = XOpenDisplay (displayName); + display = XOpenDisplay (displayName.toCString()); if (display == 0) { diff --git a/src/native/linux/juce_linux_Midi.cpp b/src/native/linux/juce_linux_Midi.cpp index 7ca71324e5..7d8df59f8c 100644 --- a/src/native/linux/juce_linux_Midi.cpp +++ b/src/native/linux/juce_linux_Midi.cpp @@ -127,8 +127,7 @@ static snd_seq_t* createDevice (const bool forInput, : SND_SEQ_OPEN_OUTPUT, 0) == 0) { snd_seq_set_client_name (seqHandle, - (const char*) (forInput ? (deviceNameToOpen + T(" Input")) - : (deviceNameToOpen + T(" Output")))); + (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString()); const int portId = snd_seq_create_simple_port (seqHandle, diff --git a/src/native/linux/juce_linux_Network.cpp b/src/native/linux/juce_linux_Network.cpp index 94b677a75f..ca39781676 100644 --- a/src/native/linux/juce_linux_Network.cpp +++ b/src/native/linux/juce_linux_Network.cpp @@ -355,7 +355,7 @@ private: numConsecutiveLFs = 0; } - const String header (String::fromUTF8 ((const uint8*) buffer.getData())); + const String header (String::fromUTF8 ((const char*) buffer.getData())); if (header.startsWithIgnoreCase (T("HTTP/"))) return header.trimEnd(); diff --git a/src/native/linux/juce_linux_SystemStats.cpp b/src/native/linux/juce_linux_SystemStats.cpp index f773d9767e..343d8231c7 100644 --- a/src/native/linux/juce_linux_SystemStats.cpp +++ b/src/native/linux/juce_linux_SystemStats.cpp @@ -226,7 +226,7 @@ const String SystemStats::getLogonName() user = pw->pw_name; } - return String::fromUTF8 ((const uint8*) user); + return String::fromUTF8 (user); } const String SystemStats::getFullUserName() diff --git a/src/native/linux/juce_linux_Threads.cpp b/src/native/linux/juce_linux_Threads.cpp index df365d6a3e..195d7fea0d 100644 --- a/src/native/linux/juce_linux_Threads.cpp +++ b/src/native/linux/juce_linux_Threads.cpp @@ -247,7 +247,7 @@ void PlatformUtilities::freeDynamicLibrary (void* handle) void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName) { - return dlsym (libraryHandle, (const char*) procedureName); + return dlsym (libraryHandle, procedureName.toCString()); } #endif diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index 2cc1635fe4..51b3c87a9e 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -1162,7 +1162,7 @@ public: KeySym sym; XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0); - const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1); + const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1); int keyCode = (int) unicodeChar; if (keyCode < 0x20) @@ -1667,7 +1667,7 @@ public: String screenAtom ("_NET_SYSTEM_TRAY_S"); screenAtom << screenNumber; - Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false); + Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false); XGrabServer (display); Window managerWin = XGetSelectionOwner (display, selectionAtom); @@ -2231,10 +2231,10 @@ private: return eventTimeOffset + thisMessageTime; } - static void setWindowTitle (Window xwin, const char* const title) throw() + static void setWindowTitle (Window xwin, const String& title) { XTextProperty nameProperty; - char* strings[] = { (char*) title }; + char* strings[] = { const_cast (title.toUTF8()) }; ScopedXLock xlock; if (XStringListToTextProperty (strings, 1, &nameProperty)) diff --git a/src/native/mac/juce_iphone_MiscUtilities.mm b/src/native/mac/juce_iphone_MiscUtilities.mm index 5953095dca..d654d575cc 100644 --- a/src/native/mac/juce_iphone_MiscUtilities.mm +++ b/src/native/mac/juce_iphone_MiscUtilities.mm @@ -61,10 +61,10 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE -int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app) +int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app) { juce_intialisingApp = app; - return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate"); + return UIApplicationMain (argc, const_cast (argv), nil, @"JuceAppStartupDelegate"); } //============================================================================== diff --git a/src/native/mac/juce_mac_AudioCDBurner.mm b/src/native/mac/juce_mac_AudioCDBurner.mm index 26d2bef9a8..fd351c4ea3 100644 --- a/src/native/mac/juce_mac_AudioCDBurner.mm +++ b/src/native/mac/juce_mac_AudioCDBurner.mm @@ -172,7 +172,7 @@ END_JUCE_NAMESPACE if ([err length] > 0) { - *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]); + *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]); break; } } @@ -465,7 +465,7 @@ const StringArray AudioCDBurner::findAvailableDevices() StringArray s; for (unsigned int i = 0; i < [names count]; ++i) - s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String])); + s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String])); return s; } diff --git a/src/native/mac/juce_mac_CoreAudio.cpp b/src/native/mac/juce_mac_CoreAudio.cpp index 6fdfaee844..26ee647509 100644 --- a/src/native/mac/juce_mac_CoreAudio.cpp +++ b/src/native/mac/juce_mac_CoreAudio.cpp @@ -153,7 +153,7 @@ public: String name; { - uint8 channelName [256]; + char channelName [256]; zerostruct (channelName); UInt32 nameSize = sizeof (channelName); UInt32 channelNum = chanNum + 1; @@ -1160,7 +1160,7 @@ public: if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name))) { - const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name))); + const String nameString (String::fromUTF8 (name, (int) strlen (name))); if (! alreadyLogged) log (T("CoreAudio device: ") + nameString); diff --git a/src/native/mac/juce_mac_Files.mm b/src/native/mac/juce_mac_Files.mm index f12edc7418..12683fb141 100644 --- a/src/native/mac/juce_mac_Files.mm +++ b/src/native/mac/juce_mac_Files.mm @@ -234,7 +234,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) case invokedExecutableFile: if (juce_Argv0 != 0) - return File (String::fromUTF8 ((const uint8*) juce_Argv0)); + return File (String::fromUTF8 (juce_Argv0)); // deliberate fall-through... case currentExecutableFile: @@ -255,7 +255,7 @@ const File File::getSpecialLocation (const SpecialLocationType type) break; } - if (resultPath != 0) + if (resultPath.isNotEmpty()) return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath)); return File::nonexistent; @@ -421,7 +421,7 @@ void juce_findFileClose (void* handle) //============================================================================== bool juce_launchExecutable (const String& pathAndArguments) { - const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 }; + const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 }; const int cpid = fork(); @@ -502,15 +502,13 @@ bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path) const String PlatformUtilities::makePathFromFSRef (FSRef* file) { - uint8 path [2048]; - zeromem (path, sizeof (path)); - - String result; + char path [2048]; + zerostruct (path); if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr) - result = String::fromUTF8 (path); + return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path)); - return PlatformUtilities::convertToPrecomposedUnicode (result); + return String::empty; } #endif diff --git a/src/native/mac/juce_mac_ObjCSuffix.h b/src/native/mac/juce_mac_ObjCSuffix.h index 6cc3d6bdb8..182ac15d18 100644 --- a/src/native/mac/juce_mac_ObjCSuffix.h +++ b/src/native/mac/juce_mac_ObjCSuffix.h @@ -40,6 +40,6 @@ #define JUCE_ObjCExtraSuffix 3 #endif -#define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d -#define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d) -#define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix) +#define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e +#define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e) +#define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix) diff --git a/src/native/mac/juce_mac_Strings.mm b/src/native/mac/juce_mac_Strings.mm index bfc95d8301..429c01089b 100644 --- a/src/native/mac/juce_mac_Strings.mm +++ b/src/native/mac/juce_mac_Strings.mm @@ -30,12 +30,12 @@ //============================================================================== static const String nsStringToJuce (NSString* s) { - return String::fromUTF8 ((uint8*) [s UTF8String]); + return String::fromUTF8 ([s UTF8String]); } static NSString* juceStringToNS (const String& s) { - return [NSString stringWithUTF8String: (const char*) s.toUTF8()]; + return [NSString stringWithUTF8String: s.toUTF8()]; } @@ -56,18 +56,11 @@ const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString) if (cfString != 0) { -#if JUCE_STRINGS_ARE_UNICODE CFRange range = { 0, CFStringGetLength (cfString) }; HeapBlock u (range.length + 1); CFStringGetCharacters (cfString, range, u); u[range.length] = 0; result = convertUTF16ToString (u); -#else - const int len = CFStringGetLength (cfString); - HeapBlock buffer (len + 1); - CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding()); - result = buffer; -#endif } return result; @@ -75,7 +68,6 @@ const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString) CFStringRef PlatformUtilities::juceStringToCFString (const String& s) { -#if JUCE_STRINGS_ARE_UNICODE const int len = s.length(); const juce_wchar* t = (const juce_wchar*) s; HeapBlock temp (len + 2); @@ -84,12 +76,6 @@ CFStringRef PlatformUtilities::juceStringToCFString (const String& s) temp[i] = t[i]; return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len); - -#else - return CFStringCreateWithCString (kCFAllocatorDefault, - (const char*) s, - CFStringGetSystemEncoding()); -#endif } const String PlatformUtilities::convertToPrecomposedUnicode (const String& s) diff --git a/src/native/windows/juce_win32_ASIO.cpp b/src/native/windows/juce_win32_ASIO.cpp index ca3390fd06..efb826990b 100644 --- a/src/native/windows/juce_win32_ASIO.cpp +++ b/src/native/windows/juce_win32_ASIO.cpp @@ -1843,38 +1843,30 @@ private: HKEY hk = 0; bool ok = false; - if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS) + if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS) { int index = 0; for (;;) { - char buf [512]; + WCHAR buf [512]; - if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS) + if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS) { if (classId.equalsIgnoreCase (buf)) { HKEY subKey, pathKey; - if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS) { - if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS) { - char pathName [600]; + WCHAR pathName [1024]; DWORD dtype = REG_SZ; DWORD dsize = sizeof (pathName); - if (RegQueryValueExA (pathKey, 0, 0, &dtype, - (LPBYTE) pathName, &dsize) == ERROR_SUCCESS) - { - OFSTRUCT of; - zerostruct (of); - - of.cBytes = sizeof (of); - - ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0); - } + if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS) + ok = File (pathName).exists(); RegCloseKey (pathKey); } @@ -1902,29 +1894,25 @@ private: { HKEY subKey; - if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) + if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) { - char buf [256]; + WCHAR buf [256]; + zerostruct (buf); DWORD dtype = REG_SZ; DWORD dsize = sizeof (buf); - zeromem (buf, dsize); - if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) + if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) { if (dsize > 0 && checkClassIsOk (buf)) { - wchar_t classIdStr [130]; - MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128); - - String deviceName; CLSID classId; - - if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK) + if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK) { dtype = REG_SZ; dsize = sizeof (buf); + String deviceName; - if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) + if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS) deviceName = buf; else deviceName = keyName; diff --git a/src/native/windows/juce_win32_DynamicLibraryLoader.cpp b/src/native/windows/juce_win32_DynamicLibraryLoader.cpp index af28b646f8..315a3b3c89 100644 --- a/src/native/windows/juce_win32_DynamicLibraryLoader.cpp +++ b/src/native/windows/juce_win32_DynamicLibraryLoader.cpp @@ -43,7 +43,7 @@ DynamicLibraryLoader::~DynamicLibraryLoader() void* DynamicLibraryLoader::findProcAddress (const String& functionName) { - return (void*) GetProcAddress ((HMODULE) libHandle, functionName); + return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString()); } diff --git a/src/native/windows/juce_win32_FileChooser.cpp b/src/native/windows/juce_win32_FileChooser.cpp index 087540c42d..722bd922da 100644 --- a/src/native/windows/juce_win32_FileChooser.cpp +++ b/src/native/windows/juce_win32_FileChooser.cpp @@ -184,7 +184,7 @@ void FileChooser::showPlatformDialog (Array& results, } else { - currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable); + currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable); initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName(); } @@ -266,9 +266,9 @@ void FileChooser::showPlatformDialog (Array& results, { WCHAR filters [1024]; zeromem (filters, sizeof (filters)); - filter.copyToBuffer (filters, 1024); - filter.copyToBuffer (filters + filter.length() + 1, - 1022 - filter.length()); + filter.copyToUnicode (filters, 1024); + filter.copyToUnicode (filters + filter.length() + 1, + 1022 - filter.length()); OPENFILENAMEW of; zerostruct (of); diff --git a/src/native/windows/juce_win32_Fonts.cpp b/src/native/windows/juce_win32_Fonts.cpp index 3652b82f5a..09904fb601 100644 --- a/src/native/windows/juce_win32_Fonts.cpp +++ b/src/native/windows/juce_win32_Fonts.cpp @@ -62,7 +62,7 @@ static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe, lf.lfPitchAndFamily = FF_DONTCARE; const String fontName (lpelfe->elfLogFont.lfFaceName); - fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1); + fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1); HDC dc = CreateCompatibleDC (0); EnumFontFamiliesEx (dc, &lf, @@ -179,7 +179,7 @@ public: lfw.lfQuality = PROOF_QUALITY; lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE); lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL; - fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1); + fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1); lfw.lfHeight = size > 0 ? size : -256; HFONT standardSizedFont = CreateFontIndirect (&lfw); diff --git a/src/native/windows/juce_win32_Misc.cpp b/src/native/windows/juce_win32_Misc.cpp index c792994acd..9f794b5cc5 100644 --- a/src/native/windows/juce_win32_Misc.cpp +++ b/src/native/windows/juce_win32_Misc.cpp @@ -44,8 +44,8 @@ void SystemClipboard::copyTextToClipboard (const String& text) throw() if (bufH != 0) { - wchar_t* const data = (wchar_t*) GlobalLock (bufH); - text.copyToBuffer (data, len); + WCHAR* const data = (WCHAR*) GlobalLock (bufH); + text.copyToUnicode (data, len); GlobalUnlock (bufH); SetClipboardData (CF_UNICODETEXT, bufH); diff --git a/src/native/windows/juce_win32_Network.cpp b/src/native/windows/juce_win32_Network.cpp index 789a22416e..e0c1f91aaf 100644 --- a/src/native/windows/juce_win32_Network.cpp +++ b/src/native/windows/juce_win32_Network.cpp @@ -444,8 +444,8 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd { MapiMessage message; zerostruct (message); - message.lpszSubject = (LPSTR) (LPCSTR) emailSubject; - message.lpszNoteText = (LPSTR) (LPCSTR) bodyText; + message.lpszSubject = (LPSTR) emailSubject.toCString(); + message.lpszNoteText = (LPSTR) bodyText.toCString(); MapiRecipDesc recip; zerostruct (recip); @@ -453,7 +453,7 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd String targetEmailAddress_ (targetEmailAddress); if (targetEmailAddress_.isEmpty()) targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address) - recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_; + recip.lpszName = (LPSTR) targetEmailAddress_.toCString(); message.nRecipCount = 1; message.lpRecips = &recip; @@ -467,7 +467,7 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd for (int i = 0; i < filesToAttach.size(); ++i) { files[i].nPosition = (ULONG) -1; - files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i]; + files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString(); } ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS); diff --git a/src/native/windows/juce_win32_Threads.cpp b/src/native/windows/juce_win32_Threads.cpp index 97c9f31f46..f53154edd9 100644 --- a/src/native/windows/juce_win32_Threads.cpp +++ b/src/native/windows/juce_win32_Threads.cpp @@ -158,7 +158,7 @@ void juce_setCurrentThreadName (const String& name) } info; info.dwType = 0x1000; - info.szName = name; + info.szName = name.toCString(); info.dwThreadID = GetCurrentThreadId(); info.dwFlags = 0; @@ -348,8 +348,7 @@ void PlatformUtilities::freeDynamicLibrary (void* h) void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name) { - return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name) - : 0; + return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0; } diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index 55095ea8de..44ed3eb86b 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -839,7 +839,7 @@ public: if (taskBarIcon != 0) { taskBarIcon->uFlags = NIF_TIP; - toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1); + toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1); Shell_NotifyIcon (NIM_MODIFY, taskBarIcon); } } @@ -2561,8 +2561,8 @@ Image* juce_createIconForFile (const File& file) { Image* image = 0; - TCHAR filename [1024]; - file.getFullPathName().copyToBuffer (filename, 1023); + WCHAR filename [1024]; + file.getFullPathName().copyToUnicode (filename, 1023); WORD iconNum = 0; HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(), @@ -3018,7 +3018,7 @@ static HDROP createHDrop (const StringArray& fileNames) throw() for (int i = 0; i < fileNames.size(); ++i) { - fileNames[i].copyToBuffer (fname, 2048); + fileNames[i].copyToUnicode (fname, 2048); fname += fileNames[i].length() + 1; } @@ -3065,7 +3065,7 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text) medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR)); char* d = (char*) GlobalLock (medium.hGlobal); - text.copyToBuffer ((WCHAR*) d, numChars + 1); + text.copyToUnicode ((WCHAR*) d, numChars + 1); format.cfFormat = CF_UNICODETEXT; GlobalUnlock (medium.hGlobal); diff --git a/src/text/juce_CharacterFunctions.cpp b/src/text/juce_CharacterFunctions.cpp index 960223098f..306ec4d8ef 100644 --- a/src/text/juce_CharacterFunctions.cpp +++ b/src/text/juce_CharacterFunctions.cpp @@ -111,6 +111,31 @@ int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int return wcsncmp (s1, s2, maxChars); } +int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw() +{ + jassert (s1 != 0 && s2 != 0); + + for (;;) + { + const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2); + + if (diff != 0) + return diff; + else if (*s1 == 0) + break; + + ++s1; + ++s2; + } + + return 0; +} + +int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw() +{ + return -compare (s2, s1); +} + int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw() { jassert (s1 != 0 && s2 != 0); @@ -481,7 +506,7 @@ double juce_atof (const CharType* const original) throw() } if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') - return atof (String (original)); // Let the c library deal with NAN and INF + return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF for (;;) { @@ -734,14 +759,14 @@ bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw() return iswalnum (character) != 0; } -int CharacterFunctions::getHexDigitValue (const tchar digit) throw() +int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw() { - if (digit >= T('0') && digit <= T('9')) - return digit - T('0'); - else if (digit >= T('a') && digit <= T('f')) - return digit - (T('a') - 10); - else if (digit >= T('A') && digit <= T('F')) - return digit - (T('A') - 10); + if (digit >= '0' && digit <= '9') + return digit - '0'; + else if (digit >= 'a' && digit <= 'f') + return digit - ('a' - 10); + else if (digit >= 'A' && digit <= 'F') + return digit - ('A' - 10); return -1; } diff --git a/src/text/juce_CharacterFunctions.h b/src/text/juce_CharacterFunctions.h index df60e29a70..22f5dfd5f0 100644 --- a/src/text/juce_CharacterFunctions.h +++ b/src/text/juce_CharacterFunctions.h @@ -28,36 +28,16 @@ //============================================================================== -/* The String class can either use wchar_t unicode characters, or 8-bit characters - (in the default system encoding) as its internal representation. +#define JUCE_T(stringLiteral) (L##stringLiteral) +typedef juce_wchar tchar; - To use unicode, define the JUCE_STRINGS_ARE_UNICODE macro in juce_Config.h - - Be sure to use "tchar" for characters rather than "char", and always wrap string - literals in the T("abcd") macro, so that it all works nicely either way round. -*/ -#if JUCE_STRINGS_ARE_UNICODE - - #define JUCE_T(stringLiteral) (L##stringLiteral) - typedef juce_wchar tchar; - #define juce_tcharToWideChar(c) (c) - -#else - - #define JUCE_T(stringLiteral) (stringLiteral) - typedef char tchar; - #define juce_tcharToWideChar(c) ((juce_wchar) (unsigned char) (c)) - -#endif #if ! JUCE_DONT_DEFINE_MACROS -/** The 'T' macro allows a literal string to be compiled using either 8-bit characters - or unicode. +/** The 'T' macro allows a literal string to be compiled as unicode. - If you write your string literals in the form T("xyz"), this will either be compiled - as "xyz" for non-unicode builds, or L"xyz" for unicode builds, depending on whether the - JUCE_STRINGS_ARE_UNICODE macro has been set in juce_Config.h + If you write your string literals in the form T("xyz"), it will be compiled as L"xyz" + or "xyz", depending on which representation is best for the String class to work with. Because the 'T' symbol is occasionally used inside 3rd-party library headers which you may need to include after juce.h, you can use the juce_withoutMacros.h file (in @@ -97,6 +77,8 @@ public: static int compare (const char* const s1, const char* const s2) throw(); static int compare (const juce_wchar* s1, const juce_wchar* s2) throw(); + static int compare (const juce_wchar* s1, const char* s2) throw(); + static int compare (const char* s1, const juce_wchar* s2) throw(); static int compare (const char* const s1, const char* const s2, const int maxChars) throw(); static int compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw(); @@ -163,7 +145,7 @@ public: /** Returns 0 to 16 for '0' to 'F", or -1 for characters that aren't a legel hex digit. */ - static int getHexDigitValue (const tchar digit) throw(); + static int getHexDigitValue (const juce_wchar digit) throw(); //============================================================================== static int printf (char* const dest, const int maxLength, const char* const format, ...) throw(); diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index 920c4d082d..d4099b5367 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -44,6 +44,10 @@ BEGIN_JUCE_NAMESPACE #pragma warning (pop) #endif +#if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE + #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default." +#endif + //============================================================================== static const char* const emptyCharString = "\0\0\0\0JUCE"; static const int safeEmptyStringRefCount = 0x3fffffff; @@ -52,7 +56,7 @@ static tchar decimalPoint = T('.'); void juce_initialiseStrings() { - decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0]; + decimalPoint = String::fromUTF8 (localeconv()->decimal_point) [0]; } //============================================================================== @@ -173,11 +177,7 @@ String::String (const char* const t) throw() const int len = CharacterFunctions::length (t); createInternal (len); -#if JUCE_STRINGS_ARE_UNICODE CharacterFunctions::copy (text->text, t, len + 1); -#else - memcpy (text->text, t, len + 1); -#endif } else { @@ -190,17 +190,9 @@ String::String (const juce_wchar* const t) throw() { if (t != 0 && *t != 0) { -#if JUCE_STRINGS_ARE_UNICODE const int len = CharacterFunctions::length (t); createInternal (len); - memcpy (text->text, t, (len + 1) * sizeof (tchar)); -#else - const int len = CharacterFunctions::bytesRequiredForCopy (t); - createInternal (len); - - CharacterFunctions::copy (text->text, t, len + 1); -#endif } else { @@ -220,13 +212,7 @@ String::String (const char* const t, if (i > 0) { createInternal (i); - -#if JUCE_STRINGS_ARE_UNICODE CharacterFunctions::copy (text->text, t, i); -#else - memcpy (text->text, t, i); -#endif - text->text [i] = 0; } else @@ -247,12 +233,7 @@ String::String (const juce_wchar* const t, if (i > 0) { createInternal (i); - -#if JUCE_STRINGS_ARE_UNICODE memcpy (text->text, t, i * sizeof (tchar)); -#else - CharacterFunctions::copy (text->text, t, i); -#endif text->text [i] = 0; } else @@ -262,7 +243,7 @@ String::String (const juce_wchar* const t, } } -const String String::charToString (const tchar character) throw() +const String String::charToString (const juce_wchar character) throw() { tchar temp[2]; temp[0] = character; @@ -271,117 +252,123 @@ const String String::charToString (const tchar character) throw() return String (temp); } -// pass in a pointer to the END of a buffer.. -static tchar* int64ToCharString (tchar* t, const int64 n) throw() +namespace IntToCharConverters { - *--t = 0; - int64 v = (n >= 0) ? n : -n; - - do + // pass in a pointer to the END of a buffer.. + static tchar* int64ToString (tchar* t, const int64 n) throw() { - *--t = (tchar) (T('0') + (int) (v % 10)); - v /= 10; + *--t = 0; + int64 v = (n >= 0) ? n : -n; - } while (v > 0); + do + { + *--t = (tchar) (T('0') + (int) (v % 10)); + v /= 10; - if (n < 0) - *--t = T('-'); + } while (v > 0); - return t; -} + if (n < 0) + *--t = T('-'); -static tchar* intToCharString (tchar* t, const int n) throw() -{ - if (n == (int) 0x80000000) // (would cause an overflow) - return int64ToCharString (t, n); + return t; + } - *--t = 0; - int v = abs (n); - - do + static tchar* uint64ToString (tchar* t, int64 v) throw() { - *--t = (tchar) (T('0') + (v % 10)); - v /= 10; + *--t = 0; - } while (v > 0); + do + { + *--t = (tchar) (T('0') + (int) (v % 10)); + v /= 10; - if (n < 0) - *--t = T('-'); + } while (v > 0); - return t; -} + return t; + } -static tchar* uintToCharString (tchar* t, unsigned int v) throw() -{ - *--t = 0; - - do + static tchar* intToString (tchar* t, const int n) throw() { - *--t = (tchar) (T('0') + (v % 10)); - v /= 10; + if (n == (int) 0x80000000) // (would cause an overflow) + return int64ToString (t, n); - } while (v > 0); + *--t = 0; + int v = abs (n); - return t; + do + { + *--t = (tchar) (T('0') + (v % 10)); + v /= 10; + + } while (v > 0); + + if (n < 0) + *--t = T('-'); + + return t; + } + + static tchar* uintToString (tchar* t, unsigned int v) throw() + { + *--t = 0; + + do + { + *--t = (tchar) (T('0') + (v % 10)); + v /= 10; + + } while (v > 0); + + return t; + } } String::String (const int number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (intToCharString (end, number), end); + createInternal (IntToCharConverters::intToString (end, number), end); } String::String (const unsigned int number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (uintToCharString (end, number), end); + createInternal (IntToCharConverters::uintToString (end, number), end); } String::String (const short number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (intToCharString (end, (int) number), end); + createInternal (IntToCharConverters::intToString (end, (int) number), end); } String::String (const unsigned short number) throw() { tchar buffer [16]; - tchar* const end = buffer + 16; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (uintToCharString (end, (unsigned int) number), end); + createInternal (IntToCharConverters::uintToString (end, (unsigned int) number), end); } String::String (const int64 number) throw() { tchar buffer [32]; - tchar* const end = buffer + 32; + tchar* const end = buffer + numElementsInArray (buffer); - createInternal (int64ToCharString (end, number), end); + createInternal (IntToCharConverters::int64ToString (end, number), end); } String::String (const uint64 number) throw() { tchar buffer [32]; - tchar* const end = buffer + 32; - tchar* t = end; + tchar* const end = buffer + numElementsInArray (buffer); - *--t = 0; - int64 v = number; - - do - { - *--t = (tchar) (T('0') + (int) (v % 10)); - v /= 10; - - } while (v > 0); - - createInternal (t, end); + createInternal (IntToCharConverters::uint64ToString (end, number), end); } // a double-to-string routine that actually uses the number of dec. places you asked for @@ -472,89 +459,6 @@ void String::preallocateStorage (const size_t numChars) throw() } } -//============================================================================== -#if JUCE_STRINGS_ARE_UNICODE -String::operator const char*() const throw() -{ - if (isEmpty()) - { - return (const char*) emptyCharString; - } - else - { - String* const mutableThis = const_cast (this); - - mutableThis->dupeInternalIfMultiplyReferenced(); - int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1; - mutableThis->text = (InternalRefCountedStringHolder*) - juce_realloc (text, sizeof (InternalRefCountedStringHolder) - + (len * sizeof (juce_wchar) + len)); - char* otherCopy = (char*) (text->text + len); - --len; - - CharacterFunctions::copy (otherCopy, text->text, len); - otherCopy [len] = 0; - return otherCopy; - } -} - -#else - -String::operator const juce_wchar*() const throw() -{ - if (isEmpty()) - { - return (const juce_wchar*) emptyCharString; - } - else - { - String* const mutableThis = const_cast (this); - - mutableThis->dupeInternalIfMultiplyReferenced(); - int len = CharacterFunctions::length (text->text) + 1; - mutableThis->text = (InternalRefCountedStringHolder*) - juce_realloc (text, sizeof (InternalRefCountedStringHolder) - + (len * sizeof (juce_wchar) + len)); - - juce_wchar* otherCopy = (juce_wchar*) (text->text + len); - --len; - - CharacterFunctions::copy (otherCopy, text->text, len); - otherCopy [len] = 0; - return otherCopy; - } -} - -#endif - -void String::copyToBuffer (char* const destBuffer, - const int bufferSizeBytes) const throw() -{ -#if JUCE_STRINGS_ARE_UNICODE - const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text)); - CharacterFunctions::copy (destBuffer, text->text, len); -#else - const int len = jmin (bufferSizeBytes, length()); - memcpy (destBuffer, text->text, len * sizeof (tchar)); -#endif - - destBuffer [len] = 0; -} - -void String::copyToBuffer (juce_wchar* const destBuffer, - const int maxCharsToCopy) const throw() -{ - const int len = jmin (maxCharsToCopy, length()); - -#if JUCE_STRINGS_ARE_UNICODE - memcpy (destBuffer, text->text, len * sizeof (juce_wchar)); -#else - CharacterFunctions::copy (destBuffer, text->text, len); -#endif - - destBuffer [len] = 0; -} - //============================================================================== int String::length() const throw() { @@ -584,12 +488,6 @@ int64 String::hashCode64() const throw() } //============================================================================== -const String& String::operator= (const tchar* const otherText) throw() -{ - operator= (String (otherText)); - return *this; -} - const String& String::operator= (const String& other) throw() { if (this != &other) @@ -608,16 +506,54 @@ const String& String::operator= (const String& other) throw() } //============================================================================== -bool String::operator== (const String& other) const throw() +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const String& string2) throw() { - return text == other.text - || CharacterFunctions::compare (text->text, other.text->text) == 0; + return string1.compare (string2) == 0; } -bool String::operator== (const tchar* const t) const throw() +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const char* string2) throw() { - return t != 0 ? CharacterFunctions::compare (text->text, t) == 0 - : isEmpty(); + return string1.compare (string2) == 0; +} + +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const juce_wchar* string2) throw() +{ + return string1.compare (string2) == 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const char* string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const juce_wchar* string2) throw() +{ + return string1.compare (string2) != 0; +} + +bool JUCE_PUBLIC_FUNCTION operator> (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) > 0; +} + +bool JUCE_PUBLIC_FUNCTION operator< (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) < 0; +} + +bool JUCE_PUBLIC_FUNCTION operator>= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) >= 0; +} + +bool JUCE_PUBLIC_FUNCTION operator<= (const String& string1, const String& string2) throw() +{ + return string1.compare (string2) <= 0; } bool String::equalsIgnoreCase (const tchar* t) const throw() @@ -632,135 +568,41 @@ bool String::equalsIgnoreCase (const String& other) const throw() || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0; } -bool String::operator!= (const String& other) const throw() +int String::compare (const String& other) const throw() { - return text != other.text - && CharacterFunctions::compare (text->text, other.text->text) != 0; + return (text == other.text) ? 0 : CharacterFunctions::compare (text->text, other.text->text); } -bool String::operator!= (const tchar* const t) const throw() +int String::compare (const char* other) const throw() { - return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0) - : isNotEmpty(); + return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other); } -bool String::operator> (const String& other) const throw() +int String::compare (const juce_wchar* other) const throw() { - return compare (other) > 0; + return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other); } -bool String::operator< (const tchar* const other) const throw() +int String::compareIgnoreCase (const String& other) const throw() { - return compare (other) < 0; + return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text->text, other.text->text); } -bool String::operator>= (const String& other) const throw() +int String::compareLexicographically (const String& other) const throw() { - return compare (other) >= 0; -} - -bool String::operator<= (const tchar* const other) const throw() -{ - return compare (other) <= 0; -} - -int String::compare (const tchar* const other) const throw() -{ - return other != 0 ? CharacterFunctions::compare (text->text, other) - : isEmpty(); -} - -int String::compareIgnoreCase (const tchar* const other) const throw() -{ - return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other) - : isEmpty(); -} - -int String::compareLexicographically (const tchar* other) const throw() -{ - if (other == 0) - return isEmpty(); - const tchar* s1 = text->text; while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1)) ++s1; - while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other)) - ++other; + const tchar* s2 = other.text->text; + while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2)) + ++s2; - return CharacterFunctions::compareIgnoreCase (s1, other); + return CharacterFunctions::compareIgnoreCase (s1, s2); } //============================================================================== -const String String::operator+ (const String& other) const throw() -{ - if (*(other.text->text) == 0) - return *this; - - if (isEmpty()) - return other; - - const int len = CharacterFunctions::length (text->text); - const int otherLen = CharacterFunctions::length (other.text->text); - - String result (len + otherLen, (int) 0); - memcpy (result.text->text, text->text, len * sizeof (tchar)); - memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar)); - result.text->text [len + otherLen] = 0; - - return result; -} - -const String String::operator+ (const tchar* const textToAppend) const throw() -{ - if (textToAppend == 0 || *textToAppend == 0) - return *this; - - const int len = CharacterFunctions::length (text->text); - const int otherLen = CharacterFunctions::length (textToAppend); - - String result (len + otherLen, (int) 0); - memcpy (result.text->text, text->text, len * sizeof (tchar)); - memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar)); - result.text->text [len + otherLen] = 0; - - return result; -} - -const String String::operator+ (const tchar characterToAppend) const throw() -{ - if (characterToAppend == 0) - return *this; - - const int len = CharacterFunctions::length (text->text); - String result ((int) (len + 1), (int) 0); - - memcpy (result.text->text, text->text, len * sizeof (tchar)); - result.text->text[len] = characterToAppend; - result.text->text[len + 1] = 0; - - return result; -} - -//============================================================================== -const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, - const String& string2) throw() -{ - String s (string1); - s += string2; - return s; -} - -const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, - const String& string2) throw() -{ - String s (string1); - s += string2; - return s; -} - -//============================================================================== -const String& String::operator+= (const tchar* const t) throw() +String& String::operator+= (const tchar* const t) { if (t != 0) appendInternal (t, CharacterFunctions::length (t)); @@ -768,49 +610,47 @@ const String& String::operator+= (const tchar* const t) throw() return *this; } -const String& String::operator+= (const String& other) throw() +String& String::operator+= (const String& other) { if (isEmpty()) operator= (other); else - appendInternal (other.text->text, - CharacterFunctions::length (other.text->text)); + appendInternal (other.text->text, other.length()); return *this; } -const String& String::operator+= (const char ch) throw() +String& String::operator+= (const char ch) { - char asString[2]; - asString[0] = ch; - asString[1] = 0; - -#if JUCE_STRINGS_ARE_UNICODE - operator+= (String (asString)); -#else - appendInternal (asString, 1); -#endif - - return *this; + const tchar asString[] = { (tchar) ch, 0 }; + return operator+= ((const tchar*) asString); } -const String& String::operator+= (const juce_wchar ch) throw() +String& String::operator+= (const juce_wchar ch) { - juce_wchar asString[2]; - asString[0] = ch; - asString[1] = 0; - -#if JUCE_STRINGS_ARE_UNICODE - appendInternal (asString, 1); -#else - operator+= (String (asString)); -#endif + const tchar asString[] = { (tchar) ch, 0 }; + return operator+= ((const tchar*) asString); +} +String& String::operator+= (const int number) +{ + tchar buffer [16]; + tchar* const end = buffer + numElementsInArray (buffer); + tchar* const start = IntToCharConverters::intToString (end, number); + appendInternal (start, end - start); return *this; } -void String::append (const tchar* const other, - const int howMany) throw() +String& String::operator+= (const unsigned int number) +{ + tchar buffer [16]; + tchar* const end = buffer + numElementsInArray (buffer); + tchar* const start = IntToCharConverters::uintToString (end, number); + appendInternal (start, end - start); + return *this; +} + +void String::append (const tchar* const other, const int howMany) { if (howMany > 0) { @@ -823,94 +663,112 @@ void String::append (const tchar* const other, } } -String& String::operator<< (const int number) throw() +//============================================================================== +const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = intToCharString (end, number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + String s (string1); + return s += string2; } -String& String::operator<< (const unsigned int number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = uintToCharString (end, number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + String s (string1); + return s += string2; } -String& String::operator<< (const short number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const char string1, const String& string2) { - tchar buffer [64]; - tchar* const end = buffer + 64; - const tchar* const t = intToCharString (end, (int) number); - appendInternal (t, (int) (end - t) - 1); - - return *this; + return String::charToString (string1) + string2; } -String& String::operator<< (const long number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar string1, const String& string2) { - return operator<< ((int) number); + return String::charToString (string1) + string2; } -String& String::operator<< (const unsigned long number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const String& string2) { - return operator<< ((unsigned int) number); + return string1 += string2; } -String& String::operator<< (const double number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char* const string2) { - operator+= (String (number)); - return *this; + return string1 += string2; } -String& String::operator<< (const float number) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar* const string2) { - operator+= (String (number)); - return *this; + return string1 += string2; } -String& String::operator<< (const char character) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char string2) { - operator+= (character); - return *this; + return string1 += string2; } -String& String::operator<< (const juce_wchar character) throw() +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar string2) { - operator+= (character); - return *this; + return string1 += string2; } -String& String::operator<< (const char* const t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char characterToAppend) { -#if JUCE_STRINGS_ARE_UNICODE - operator+= (String (t)); -#else - operator+= (t); -#endif - return *this; + return string1 += characterToAppend; } -String& String::operator<< (const juce_wchar* const t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar characterToAppend) { -#if JUCE_STRINGS_ARE_UNICODE - operator+= (t); -#else - operator+= (String (t)); -#endif - return *this; + return string1 += characterToAppend; } -String& String::operator<< (const String& t) throw() +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char* const string2) { - operator+= (t); - return *this; + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar* const string2) +{ + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const String& string2) +{ + return string1 += string2; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const short number) +{ + return string1 += (int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const int number) +{ + return string1 += number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned int number) +{ + return string1 += number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const long number) +{ + return string1 += (int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned long number) +{ + return string1 += (unsigned int) number; +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const float number) +{ + return string1 += String (number); +} + +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const double number) +{ + return string1 += String (number); } //============================================================================== @@ -1505,7 +1363,7 @@ const String String::toLowerCase() const throw() } //============================================================================== -tchar& String::operator[] (const int index) throw() +juce_wchar& String::operator[] (const int index) throw() { jassert (((unsigned int) index) <= (unsigned int) length()); @@ -1514,9 +1372,9 @@ tchar& String::operator[] (const int index) throw() return text->text [index]; } -tchar String::getLastCharacter() const throw() +juce_wchar String::getLastCharacter() const throw() { - return (isEmpty()) ? ((tchar) 0) + return (isEmpty()) ? ((juce_wchar) 0) : text->text [CharacterFunctions::length (text->text) - 1]; } @@ -2060,12 +1918,12 @@ const String String::createStringFromData (const void* const data_, } else { - return String::fromUTF8 ((const uint8*) data, size); + return String::fromUTF8 (data, size); } } //============================================================================== -const char* String::toUTF8() const throw() +const char* String::toUTF8() const { if (isEmpty()) { @@ -2078,24 +1936,23 @@ const char* String::toUTF8() const throw() mutableThis->dupeInternalIfMultiplyReferenced(); const int currentLen = CharacterFunctions::length (text->text) + 1; - const int utf8BytesNeeded = copyToUTF8 (0); + const int utf8BytesNeeded = getNumBytesAsUTF8() + 1; mutableThis->text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder) + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded)); char* const otherCopy = (char*) (text->text + currentLen); - copyToUTF8 ((uint8*) otherCopy); + copyToUTF8 (otherCopy, std::numeric_limits::max()); return otherCopy; } } -int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw() +int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw() { jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied! -#if JUCE_STRINGS_ARE_UNICODE int num = 0, index = 0; for (;;) @@ -2165,18 +2022,46 @@ int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const } return num; - -#else - const int numBytes = jmin (maxBufferSizeBytes, length() + 1); - - if (buffer != 0) - copyToBuffer ((char*) buffer, maxBufferSizeBytes); - - return numBytes; -#endif } -const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw() +int String::getNumBytesAsUTF8() const throw() +{ + int num = 0; + const juce_wchar* t = text->text; + + for (;;) + { + const uint32 c = (uint32) *t; + + if (c >= 0x80) + { + ++num; + if (c >= 0x800) + { + ++num; + if (c >= 0x10000) + { + ++num; + if (c >= 0x200000) + { + ++num; + if (c >= 0x4000000) + ++num; + } + } + } + } + else if (c == 0) + break; + + ++num; + ++t; + } + + return num; +} + +const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) { if (buffer == 0) return empty; @@ -2190,16 +2075,16 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t break; String result ((int) numBytes + 1, 0); - tchar* dest = result.text->text; + juce_wchar* dest = result.text->text; size_t i = 0; while (i < numBytes) { - const uint8 c = buffer [i++]; + const char c = buffer [i++]; - if ((c & 0x80) != 0) + if (c < 0) { - int mask = 0x7f; + unsigned int mask = 0x7f; int bit = 0x40; int numExtraValues = 0; @@ -2210,11 +2095,11 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t ++numExtraValues; } - int n = (c & mask); + int n = (mask & (unsigned char) c); while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes) { - const uint8 nextByte = buffer[i]; + const char nextByte = buffer[i]; if ((nextByte & 0xc0) != 0x80) break; @@ -2224,11 +2109,11 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t ++i; } - *dest++ = (tchar) n; + *dest++ = (juce_wchar) n; } else { - *dest++ = (tchar) c; + *dest++ = (juce_wchar) c; } } @@ -2236,6 +2121,55 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t return result; } +//============================================================================== +const char* String::toCString() const +{ + if (isEmpty()) + { + return (const char*) emptyCharString; + } + else + { + String* const mutableThis = const_cast (this); + + mutableThis->dupeInternalIfMultiplyReferenced(); + int len = length() + 1; + mutableThis->text = (InternalRefCountedStringHolder*) + juce_realloc (text, sizeof (InternalRefCountedStringHolder) + + (len * sizeof (juce_wchar) + len)); + char* otherCopy = (char*) (text->text + len); + --len; + + CharacterFunctions::copy (otherCopy, text->text, len); + otherCopy [len] = 0; + return otherCopy; + } +} + +int String::getNumBytesAsCString() const throw() +{ + return (int) wcstombs (0, text->text, 0); +} + +int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw() +{ + const int numBytes = (int) wcstombs (destBuffer, text->text, maxBufferSizeBytes); + + if (destBuffer != 0 && numBytes >= 0) + destBuffer [numBytes] = 0; + + return numBytes; +} + +//============================================================================== +void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw() +{ + const int len = jmin (maxCharsToCopy, length()); + memcpy (destBuffer, text->text, len * sizeof (juce_wchar)); + destBuffer [len] = 0; +} + + //============================================================================== String::Concatenator::Concatenator (String& stringToAppendTo) : result (stringToAppendTo), @@ -2254,7 +2188,7 @@ void String::Concatenator::append (const String& s) if (len > 0) { result.preallocateStorage (nextIndex + len); - s.copyToBuffer (const_cast ((const tchar*) result) + nextIndex, len); + s.copyToUnicode (((juce_wchar*) result) + nextIndex, len); nextIndex += len; } } diff --git a/src/text/juce_String.h b/src/text/juce_String.h index ffbe87f2d3..58a1cdc627 100644 --- a/src/text/juce_String.h +++ b/src/text/juce_String.h @@ -78,7 +78,7 @@ public: const size_t maxChars) throw(); /** Creates a string from a single character. */ - static const String charToString (const tchar character) throw(); + static const String charToString (const juce_wchar character) throw(); /** Destructor. */ ~String() throw(); @@ -104,20 +104,21 @@ public: //============================================================================== // Assignment and concatenation operators.. - /** Replaces this string's contents with another string. */ - const String& operator= (const tchar* const other) throw(); - /** Replaces this string's contents with another string. */ const String& operator= (const String& other) throw(); /** Appends another string at the end of this one. */ - const String& operator+= (const tchar* const textToAppend) throw(); + String& operator+= (const tchar* const textToAppend); /** Appends another string at the end of this one. */ - const String& operator+= (const String& stringToAppend) throw(); + String& operator+= (const String& stringToAppend); /** Appends a character at the end of this string. */ - const String& operator+= (const char characterToAppend) throw(); + String& operator+= (const char characterToAppend); /** Appends a character at the end of this string. */ - const String& operator+= (const juce_wchar characterToAppend) throw(); + String& operator+= (const juce_wchar characterToAppend); + /** Appends a decimal number at the end of this string. */ + String& operator+= (const int numberToAppend); + /** Appends a decimal number at the end of this string. */ + String& operator+= (const unsigned int numberToAppend); /** Appends a string at the end of this one. @@ -125,48 +126,7 @@ public: @param maxCharsToTake the maximum number of characters to take from the string passed in */ void append (const tchar* const textToAppend, - const int maxCharsToTake) throw(); - - /** Appends a string at the end of this one. - @returns the concatenated string - */ - const String operator+ (const String& stringToAppend) const throw(); - - /** Appends a string at the end of this one. - @returns the concatenated string - */ - const String operator+ (const tchar* const textToAppend) const throw(); - - /** Appends a character at the end of this one. - @returns the concatenated string - */ - const String operator+ (const tchar characterToAppend) const throw(); - - /** Appends a character at the end of this string. */ - String& operator<< (const char n) throw(); - /** Appends a character at the end of this string. */ - String& operator<< (const juce_wchar n) throw(); - /** Appends another string at the end of this one. */ - String& operator<< (const char* const text) throw(); - /** Appends another string at the end of this one. */ - String& operator<< (const juce_wchar* const text) throw(); - /** Appends another string at the end of this one. */ - String& operator<< (const String& text) throw(); - - /** Appends a decimal number at the end of this string. */ - String& operator<< (const short number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const int number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const unsigned int number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const long number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const unsigned long number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const float number) throw(); - /** Appends a decimal number at the end of this string. */ - String& operator<< (const double number) throw(); + const int maxCharsToTake); //============================================================================== // Comparison methods.. @@ -187,44 +147,38 @@ public: */ inline bool isNotEmpty() const throw() { return text->text[0] != 0; } - /** Case-sensitive comparison with another string. */ - bool operator== (const String& other) const throw(); - /** Case-sensitive comparison with another string. */ - bool operator== (const tchar* const other) const throw(); - - /** Case-sensitive comparison with another string. */ - bool operator!= (const String& other) const throw(); - /** Case-sensitive comparison with another string. */ - bool operator!= (const tchar* const other) const throw(); - /** Case-insensitive comparison with another string. */ bool equalsIgnoreCase (const String& other) const throw(); /** Case-insensitive comparison with another string. */ bool equalsIgnoreCase (const tchar* const other) const throw(); - /** Case-sensitive comparison with another string. */ - bool operator> (const String& other) const throw(); - /** Case-sensitive comparison with another string. */ - bool operator< (const tchar* const other) const throw(); - - /** Case-sensitive comparison with another string. */ - bool operator>= (const String& other) const throw(); - /** Case-sensitive comparison with another string. */ - bool operator<= (const tchar* const other) const throw(); - /** Case-sensitive comparison with another string. @returns 0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it. */ - int compare (const tchar* const other) const throw(); + int compare (const String& other) const throw(); + + /** Case-sensitive comparison with another string. + @returns 0 if the two strings are identical; negative if this string + comes before the other one alphabetically, or positive if it + comes after it. + */ + int compare (const char* other) const throw(); + + /** Case-sensitive comparison with another string. + @returns 0 if the two strings are identical; negative if this string + comes before the other one alphabetically, or positive if it + comes after it. + */ + int compare (const juce_wchar* other) const throw(); /** Case-insensitive comparison with another string. @returns 0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it. */ - int compareIgnoreCase (const tchar* const other) const throw(); + int compareIgnoreCase (const String& other) const throw(); /** Lexicographic comparison with another string. @@ -235,58 +189,49 @@ public: comes before the other one alphabetically, or positive if it comes after it. */ - int compareLexicographically (const tchar* const other) const throw(); + int compareLexicographically (const String& other) const throw(); /** Tests whether the string begins with another string. - Uses a case-sensitive comparison. */ bool startsWith (const tchar* const text) const throw(); /** Tests whether the string begins with a particular character. - Uses a case-sensitive comparison. */ bool startsWithChar (const tchar character) const throw(); /** Tests whether the string begins with another string. - Uses a case-insensitive comparison. */ bool startsWithIgnoreCase (const tchar* const text) const throw(); /** Tests whether the string ends with another string. - Uses a case-sensitive comparison. */ bool endsWith (const tchar* const text) const throw(); /** Tests whether the string ends with a particular character. - Uses a case-sensitive comparison. */ bool endsWithChar (const tchar character) const throw(); /** Tests whether the string ends with another string. - Uses a case-insensitive comparison. */ bool endsWithIgnoreCase (const tchar* const text) const throw(); /** Tests whether the string contains another substring. - Uses a case-sensitive comparison. */ bool contains (const tchar* const text) const throw(); /** Tests whether the string contains a particular character. - Uses a case-sensitive comparison. */ bool containsChar (const tchar character) const throw(); /** Tests whether the string contains another substring. - Uses a case-insensitive comparison. */ bool containsIgnoreCase (const tchar* const text) const throw(); @@ -488,7 +433,7 @@ public: No checks are made to see if the index is within a valid range, so be careful! */ - inline const tchar& operator[] (const int index) const throw() { jassert (((unsigned int) index) <= (unsigned int) length()); return text->text [index]; } + inline const juce_wchar& operator[] (const int index) const throw() { jassert (((unsigned int) index) <= (unsigned int) length()); return text->text [index]; } /** Returns a character from the string such that it can also be altered. @@ -497,13 +442,13 @@ public: Note that the index passed-in is not checked to see whether it's in-range, so be careful when using this. */ - tchar& operator[] (const int index) throw(); + juce_wchar& operator[] (const int index) throw(); /** Returns the final character of the string. If the string is empty this will return 0. */ - tchar getLastCharacter() const throw(); + juce_wchar getLastCharacter() const throw(); //============================================================================== /** Returns a subsection of the string. @@ -962,63 +907,46 @@ public: const int groupSize = 1) throw(); //============================================================================== - // Casting to character arrays.. - -#if JUCE_STRINGS_ARE_UNICODE - /** Returns a version of this string using the default 8-bit system encoding. - - 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. - */ - operator const char*() const throw(); - /** Returns a unicode 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. + that is returned must not be stored anywhere, as it can become invalid whenever + any string methods (even some const ones!) are called. */ inline operator const juce_wchar*() const throw() { return text->text; } -#else - /** Returns a version of this string using the default 8-bit system encoding. - - 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. - */ - inline operator const char*() const throw() { return text->text; } + //============================================================================== /** Returns a unicode 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. + that is returned must not be stored anywhere, as it can become invalid whenever + any string methods (even some const ones!) are called. */ - operator const juce_wchar*() const throw(); -#endif - - /** Copies the string to a buffer. - - @param destBuffer the place to copy it to - @param maxCharsToCopy the maximum number of characters to copy to the buffer, - not including the tailing zero, so this shouldn't be - larger than the size of your destination buffer - 1 - */ - void copyToBuffer (char* const destBuffer, - const int maxCharsToCopy) const throw(); - - /** Copies the string to a unicode buffer. - - @param destBuffer the place to copy it to - @param maxCharsToCopy the maximum number of characters to copy to the buffer, - not including the tailing zero, so this shouldn't be - larger than the size of your destination buffer - 1 - */ - void copyToBuffer (juce_wchar* const destBuffer, - const int maxCharsToCopy) const throw(); + inline operator juce_wchar*() throw() { return text->text; } //============================================================================== + /** 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. + + @see getNumBytesAsUTF8, fromUTF8, copyToUTF8, toCString + */ + const char* toUTF8() const; + + /** Creates a String from a UTF-8 encoded buffer. + + If the size is < 0, it'll keep reading until it hits a zero. + */ + static const String fromUTF8 (const char* utf8buffer, int bufferSizeBytes = -1); + + /** Returns the number of bytes required to represent this string as UTF8. + The number returned does NOT include the trailing zero. + @see toUTF8, copyToUTF8 + */ + int getNumBytesAsUTF8() const throw(); + /** Copies the string to a buffer as UTF-8 characters. Returns the number of bytes copied to the buffer, including the terminating null @@ -1029,26 +957,48 @@ public: (including the terminating null character). @param maxBufferSizeBytes the size of the destination buffer, in bytes. If the string won't fit, it'll put in as many as it can while - still allowing for a terminating null char at the end, - and will return the number of bytes that were actually - used. If this value is < 0, no limit is used. + still allowing for a terminating null char at the end, and + will return the number of bytes that were actually used. */ - int copyToUTF8 (uint8* const destBuffer, const int maxBufferSizeBytes = 0x7fffffff) const throw(); + int copyToUTF8 (char* destBuffer, const int maxBufferSizeBytes) const throw(); - /** Returns a pointer to a UTF-8 version of this string. + //============================================================================== + /** Returns a version of this string using the default 8-bit multi-byte system encoding. 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. - */ - const char* toUTF8() const throw(); - /** Creates a String from a UTF-8 encoded buffer. - - If the size is < 0, it'll keep reading until it hits a zero. + @see getNumBytesAsCString, copyToCString, toUTF8 */ - static const String fromUTF8 (const uint8* const utf8buffer, - int bufferSizeBytes = -1) throw(); + const char* toCString() const; + + /** Returns the number of bytes + */ + int getNumBytesAsCString() const throw(); + + /** Copies the string to a buffer. + + @param destBuffer the place to copy it to; if this is a null pointer, + the method just returns the number of bytes required + (including the terminating null character). + @param maxBufferSizeBytes the size of the destination buffer, in bytes. If the + string won't fit, it'll put in as many as it can while + still allowing for a terminating null char at the end, and + will return the number of bytes that were actually used. + */ + int copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw(); + + //============================================================================== + /** Copies the string to a unicode buffer. + + @param destBuffer the place to copy it to + @param maxCharsToCopy the maximum number of characters to copy to the buffer, + not including the tailing zero, so this shouldn't be + larger than the size of your destination buffer - 1 + */ + void copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw(); + //============================================================================== /** Increases the string's internally allocated storage. @@ -1102,12 +1052,7 @@ private: { int refCount; int allocatedNumChars; - -#if JUCE_STRINGS_ARE_UNICODE - wchar_t text[1]; -#else - char text[1]; -#endif + wchar_t text[1]; }; InternalRefCountedStringHolder* text; @@ -1125,25 +1070,81 @@ private: }; //============================================================================== -/** Global operator to allow a String to be appended to a string literal. +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (const char* string1, const String& string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* string1, const String& string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (char string1, const String& string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (juce_wchar string1, const String& string2); - This allows the use of expressions such as "abc" + String (x) +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const String& string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char* string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar* string2); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, char characterToAppend); +/** Concatenates two strings. */ +const String JUCE_PUBLIC_FUNCTION operator+ (String string1, juce_wchar characterToAppend); - @see String - */ -const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, - const String& string2) throw(); +/** Appends a character at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char characterToAppend); +/** Appends a character at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar characterToAppend); +/** Appends a string to the end of the first one. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char* const string2); +/** Appends a string to the end of the first one. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar* const string2); +/** Appends a string to the end of the first one. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const String& string2); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const short number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const int number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned int number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const long number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned long number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const float number); +/** Appends a decimal number at the end of a string. */ +String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const double number); -//============================================================================== -/** Global operator to allow a String to be appended to a string literal. +/** This streaming override allows you to pass a juce String directly into std output streams. + This is very handy for writing strings to std::cout, std::cerr, etc. +*/ +template +std::basic_ostream & operator<< (std::basic_ostream & stream, const String& stringToWrite) +{ + return stream << stringToWrite.toUTF8(); +} - This allows the use of expressions such as "abc" + String (x) - - @see String - */ -const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, - const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const char* string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const juce_wchar* string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const char* string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const juce_wchar* string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator> (const String& string1, const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator< (const String& string1, const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator>= (const String& string1, const String& string2) throw(); +/** Case-sensitive comparison of two strings. */ +bool JUCE_PUBLIC_FUNCTION operator<= (const String& string1, const String& string2) throw(); #endif // __JUCE_STRING_JUCEHEADER__ diff --git a/src/text/juce_StringArray.cpp b/src/text/juce_StringArray.cpp index 7b8879472c..a49d18c3f3 100644 --- a/src/text/juce_StringArray.cpp +++ b/src/text/juce_StringArray.cpp @@ -302,7 +302,7 @@ const String StringArray::joinIntoString (const String& separator, int start, in String result; result.preallocateStorage (charsNeeded); - tchar* dest = (tchar*) (const tchar*) result; + juce_wchar* dest = (juce_wchar*) result; while (start < last) { @@ -311,13 +311,13 @@ const String StringArray::joinIntoString (const String& separator, int start, in if (len > 0) { - s.copyToBuffer (dest, len); + s.copyToUnicode (dest, len); dest += len; } if (++start < last && separatorLen > 0) { - separator.copyToBuffer (dest, separatorLen); + separator.copyToUnicode (dest, separatorLen); dest += separatorLen; } } diff --git a/src/text/juce_XmlDocument.cpp b/src/text/juce_XmlDocument.cpp index 62e8010360..6ef6cd7393 100644 --- a/src/text/juce_XmlDocument.cpp +++ b/src/text/juce_XmlDocument.cpp @@ -94,7 +94,7 @@ XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentEle } else { - textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize()); + textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize()); } if (! onlyReadOuterDocumentElement) diff --git a/src/text/juce_XmlElement.cpp b/src/text/juce_XmlElement.cpp index 8b6dd03671..bf3b9d75a5 100644 --- a/src/text/juce_XmlElement.cpp +++ b/src/text/juce_XmlElement.cpp @@ -271,10 +271,9 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, if (! isTextElement()) { outputStream.writeByte ('<'); - const int nameLen = tagName.length(); - outputStream.write ((const char*) tagName, nameLen); + outputStream << tagName; - const int attIndent = indentationLevel + nameLen + 1; + const int attIndent = indentationLevel + tagName.length() + 1; int lineLen = 0; const XmlAttributeNode* att = attributes; @@ -287,13 +286,13 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, lineLen = 0; } - const int attNameLen = att->name.length(); + const int64 startPos = outputStream.getPosition(); outputStream.writeByte (' '); - outputStream.write ((const char*) (att->name), attNameLen); + outputStream << att->name; outputStream.write ("=\"", 2); escapeIllegalXmlChars (outputStream, att->value, true); outputStream.writeByte ('"'); - lineLen += 4 + attNameLen + att->value.length(); + lineLen += (int) (outputStream.getPosition() - startPos); att = att->next; } @@ -356,7 +355,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, } outputStream.write ("= 0) outputStream.write (">\r\n", 3);