diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index ec54aea3b9..e859db6490 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -7629,25 +7629,25 @@ const String File::addTrailingSeparator (const String& path) } #if JUCE_LINUX - #define NAMES_ARE_CASE_SENSITIVE 1 + #define NAMES_ARE_CASE_SENSITIVE 1 #endif bool File::areFileNamesCaseSensitive() { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return true; -#else + #else return false; -#endif + #endif } bool File::operator== (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath == other.fullPath; -#else + #else return fullPath.equalsIgnoreCase (other.fullPath); -#endif + #endif } bool File::operator!= (const File& other) const @@ -7657,20 +7657,20 @@ bool File::operator!= (const File& other) const bool File::operator< (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath < other.fullPath; -#else + #else return fullPath.compareIgnoreCase (other.fullPath) < 0; -#endif + #endif } bool File::operator> (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath > other.fullPath; -#else + #else return fullPath.compareIgnoreCase (other.fullPath) > 0; -#endif + #endif } bool File::setReadOnly (const bool shouldBeReadOnly, @@ -7711,9 +7711,9 @@ bool File::moveFileTo (const File& newFile) const if (newFile.fullPath == fullPath) return true; -#if ! NAMES_ARE_CASE_SENSITIVE + #if ! NAMES_ARE_CASE_SENSITIVE if (*this != newFile) -#endif + #endif if (! newFile.deleteFile()) return false; @@ -7801,11 +7801,11 @@ bool File::isAChildOf (const File& potentialParent) const const String ourPath (getPathUpToLastSlash()); -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE if (potentialParent.fullPath == ourPath) -#else + #else if (potentialParent.fullPath.equalsIgnoreCase (ourPath)) -#endif + #endif { return true; } @@ -7888,26 +7888,11 @@ const File File::getSiblingFile (const String& fileName) const const String File::descriptionOfSizeInBytes (const int64 bytes) { - if (bytes == 1) - { - return "1 byte"; - } - else if (bytes < 1024) - { - return String ((int) bytes) + " bytes"; - } - else if (bytes < 1024 * 1024) - { - return String (bytes / 1024.0, 1) + " KB"; - } - else if (bytes < 1024 * 1024 * 1024) - { - return String (bytes / (1024.0 * 1024.0), 1) + " MB"; - } - else - { - return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB"; - } + if (bytes == 1) return "1 byte"; + else if (bytes < 1024) return String (bytes) + " bytes"; + else if (bytes < 1024 * 1024) return String (bytes / 1024.0, 1) + " KB"; + else if (bytes < 1024 * 1024 * 1024) return String (bytes / (1024.0 * 1024.0), 1) + " MB"; + else return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB"; } bool File::create() const @@ -7943,26 +7928,9 @@ bool File::createDirectory() const return true; } -const Time File::getCreationTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (c); -} - -const Time File::getLastModificationTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (m); -} - -const Time File::getLastAccessTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (a); -} +const Time File::getLastModificationTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (m); } +const Time File::getLastAccessTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (a); } +const Time File::getCreationTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (c); } bool File::setLastModificationTime (const Time& t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); } bool File::setLastAccessTime (const Time& t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); } @@ -8041,7 +8009,7 @@ const File File::getNonexistentChildFile (const String& prefix_, { putNumbersInBrackets = true; - const int openBracks = prefix.lastIndexOfChar ('('); + const int openBracks = prefix.lastIndexOfChar ('('); const int closeBracks = prefix.lastIndexOfChar (')'); if (openBracks > 0 @@ -8059,10 +8027,14 @@ const File File::getNonexistentChildFile (const String& prefix_, do { + String newName (prefix); + if (putNumbersInBrackets) - f = getChildFile (prefix + '(' + String (num++) + ')' + suffix); + newName << '(' << num++ << ')'; else - f = getChildFile (prefix + String (num++) + suffix); + newName << num++; + + f = getChildFile (newName + suffix); } while (f.exists()); } @@ -8073,16 +8045,11 @@ const File File::getNonexistentChildFile (const String& prefix_, const File File::getNonexistentSibling (const bool putNumbersInBrackets) const { if (exists()) - { return getParentDirectory() .getNonexistentChildFile (getFileNameWithoutExtension(), getFileExtension(), putNumbersInBrackets); - } - else - { - return *this; - } + return *this; } const String File::getFileExtension() const @@ -8232,9 +8199,7 @@ bool File::hasIdenticalContentTo (const File& other) const FileInputStream in1 (*this), in2 (other); const int bufferSize = 4096; - HeapBlock buffer1, buffer2; - buffer1.malloc (bufferSize); - buffer2.malloc (bufferSize); + HeapBlock buffer1 (bufferSize), buffer2 (bufferSize); for (;;) { @@ -8341,11 +8306,11 @@ const String File::getRelativePathFrom (const File& dir) const while (dirPath.isNotEmpty()) { -#if JUCE_WINDOWS + #if JUCE_WINDOWS thisPath = "..\\" + thisPath; -#else + #else thisPath = "../" + thisPath; -#endif + #endif const int sep = dirPath.indexOfChar (separator); @@ -8366,8 +8331,8 @@ const File File::createTempFile (const String& fileNameEnding) if (tempFile.exists()) return createTempFile (fileNameEnding); - else - return tempFile; + + return tempFile; } #if JUCE_UNIT_TESTS @@ -14307,48 +14272,25 @@ int StringArray::addTokens (const String& text, const String& breakCharacters, c if (text.isNotEmpty()) { - bool insideQuotes = false; - juce_wchar currentQuoteChar = 0; - String::CharPointerType t (text.getCharPointer()); - String::CharPointerType tokenStart (t); - int numChars = 0; for (;;) { - const juce_wchar c = t.getAndAdvance(); - ++numChars; + String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t, + breakCharacters.getCharPointer(), + quoteCharacters.getCharPointer())); - const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c)); + if (tokenEnd == t) + break; - if (! isBreak) - { - if (quoteCharacters.containsChar (c)) - { - if (insideQuotes) - { - // only break out of quotes-mode if we find a matching quote to the - // one that we opened with.. - if (currentQuoteChar == c) - insideQuotes = false; - } - else - { - insideQuotes = true; - currentQuoteChar = c; - } - } - } - else - { - add (String (tokenStart, numChars - 1)); - ++num; - tokenStart = t; - numChars = 0; - } + add (String (t, tokenEnd)); + ++num; + t = tokenEnd; - if (c == 0) + if (t.isEmpty()) break; + + ++t; } } @@ -244430,9 +244372,7 @@ void PlatformUtilities::registerFileAssociation (const String& fileExtension, targetExecutable.getFullPathName() + "," + String (-iconResourceNumber)); setRegistryValue (key + "\\", fullDescription); - - setRegistryValue (key + "\\shell\\open\\command\\", - targetExecutable.getFullPathName() + " %1"); + setRegistryValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " %1"); } bool juce_IsRunningInWine() @@ -244449,12 +244389,10 @@ bool juce_IsRunningInWine() const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() { - String s (::GetCommandLineW()); - - StringArray tokens; - tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument - - return tokens.joinIntoString (" ", 1); + const String commandLine (GetCommandLineW()); + return String (CharacterFunctions::findEndOfToken (commandLine.getCharPointer(), + String (" ").getCharPointer(), + String ("\"").getCharPointer())).trimStart(); } static void* currentModuleHandle = 0; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 1e4bce8d37..7d6e7be965 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -2079,6 +2079,34 @@ public: return p; } + template + static Type findEndOfToken (const Type& text, const Type& breakCharacters, const Type& quoteCharacters) + { + Type t (text); + juce_wchar currentQuoteChar = 0; + + while (! t.isEmpty()) + { + const juce_wchar c = t.getAndAdvance(); + + if (currentQuoteChar == 0 && breakCharacters.indexOf (c) >= 0) + { + --t; + break; + } + + if (quoteCharacters.indexOf (c) >= 0) + { + if (currentQuoteChar == 0) + currentQuoteChar = c; + else if (currentQuoteChar == c) + currentQuoteChar = 0; + } + } + + return t; + } + private: static double mulexp10 (const double value, int exponent) throw(); }; diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 4935f3b7c9..33b6e1cbba 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -173,25 +173,25 @@ const String File::addTrailingSeparator (const String& path) //============================================================================== #if JUCE_LINUX - #define NAMES_ARE_CASE_SENSITIVE 1 + #define NAMES_ARE_CASE_SENSITIVE 1 #endif bool File::areFileNamesCaseSensitive() { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return true; -#else + #else return false; -#endif + #endif } bool File::operator== (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath == other.fullPath; -#else + #else return fullPath.equalsIgnoreCase (other.fullPath); -#endif + #endif } bool File::operator!= (const File& other) const @@ -201,20 +201,20 @@ bool File::operator!= (const File& other) const bool File::operator< (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath < other.fullPath; -#else + #else return fullPath.compareIgnoreCase (other.fullPath) < 0; -#endif + #endif } bool File::operator> (const File& other) const { -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE return fullPath > other.fullPath; -#else + #else return fullPath.compareIgnoreCase (other.fullPath) > 0; -#endif + #endif } //============================================================================== @@ -256,9 +256,9 @@ bool File::moveFileTo (const File& newFile) const if (newFile.fullPath == fullPath) return true; -#if ! NAMES_ARE_CASE_SENSITIVE + #if ! NAMES_ARE_CASE_SENSITIVE if (*this != newFile) -#endif + #endif if (! newFile.deleteFile()) return false; @@ -348,11 +348,11 @@ bool File::isAChildOf (const File& potentialParent) const const String ourPath (getPathUpToLastSlash()); -#if NAMES_ARE_CASE_SENSITIVE + #if NAMES_ARE_CASE_SENSITIVE if (potentialParent.fullPath == ourPath) -#else + #else if (potentialParent.fullPath.equalsIgnoreCase (ourPath)) -#endif + #endif { return true; } @@ -437,26 +437,11 @@ const File File::getSiblingFile (const String& fileName) const //============================================================================== const String File::descriptionOfSizeInBytes (const int64 bytes) { - if (bytes == 1) - { - return "1 byte"; - } - else if (bytes < 1024) - { - return String ((int) bytes) + " bytes"; - } - else if (bytes < 1024 * 1024) - { - return String (bytes / 1024.0, 1) + " KB"; - } - else if (bytes < 1024 * 1024 * 1024) - { - return String (bytes / (1024.0 * 1024.0), 1) + " MB"; - } - else - { - return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB"; - } + if (bytes == 1) return "1 byte"; + else if (bytes < 1024) return String (bytes) + " bytes"; + else if (bytes < 1024 * 1024) return String (bytes / 1024.0, 1) + " KB"; + else if (bytes < 1024 * 1024 * 1024) return String (bytes / (1024.0 * 1024.0), 1) + " MB"; + else return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB"; } //============================================================================== @@ -494,26 +479,9 @@ bool File::createDirectory() const } //============================================================================== -const Time File::getCreationTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (c); -} - -const Time File::getLastModificationTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (m); -} - -const Time File::getLastAccessTime() const -{ - int64 m, a, c; - getFileTimesInternal (m, a, c); - return Time (a); -} +const Time File::getLastModificationTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (m); } +const Time File::getLastAccessTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (a); } +const Time File::getCreationTime() const { int64 m, a, c; getFileTimesInternal (m, a, c); return Time (c); } bool File::setLastModificationTime (const Time& t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); } bool File::setLastAccessTime (const Time& t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); } @@ -595,7 +563,7 @@ const File File::getNonexistentChildFile (const String& prefix_, { putNumbersInBrackets = true; - const int openBracks = prefix.lastIndexOfChar ('('); + const int openBracks = prefix.lastIndexOfChar ('('); const int closeBracks = prefix.lastIndexOfChar (')'); if (openBracks > 0 @@ -613,10 +581,14 @@ const File File::getNonexistentChildFile (const String& prefix_, do { + String newName (prefix); + if (putNumbersInBrackets) - f = getChildFile (prefix + '(' + String (num++) + ')' + suffix); + newName << '(' << num++ << ')'; else - f = getChildFile (prefix + String (num++) + suffix); + newName << num++; + + f = getChildFile (newName + suffix); } while (f.exists()); } @@ -627,16 +599,11 @@ const File File::getNonexistentChildFile (const String& prefix_, const File File::getNonexistentSibling (const bool putNumbersInBrackets) const { if (exists()) - { return getParentDirectory() .getNonexistentChildFile (getFileNameWithoutExtension(), getFileExtension(), putNumbersInBrackets); - } - else - { - return *this; - } + return *this; } //============================================================================== @@ -790,9 +757,7 @@ bool File::hasIdenticalContentTo (const File& other) const FileInputStream in1 (*this), in2 (other); const int bufferSize = 4096; - HeapBlock buffer1, buffer2; - buffer1.malloc (bufferSize); - buffer2.malloc (bufferSize); + HeapBlock buffer1 (bufferSize), buffer2 (bufferSize); for (;;) { @@ -901,11 +866,11 @@ const String File::getRelativePathFrom (const File& dir) const while (dirPath.isNotEmpty()) { -#if JUCE_WINDOWS + #if JUCE_WINDOWS thisPath = "..\\" + thisPath; -#else + #else thisPath = "../" + thisPath; -#endif + #endif const int sep = dirPath.indexOfChar (separator); @@ -927,10 +892,12 @@ const File File::createTempFile (const String& fileNameEnding) if (tempFile.exists()) return createTempFile (fileNameEnding); - else - return tempFile; + + return tempFile; } + +//============================================================================== #if JUCE_UNIT_TESTS #include "../../utilities/juce_UnitTest.h" diff --git a/src/native/windows/juce_win32_PlatformUtils.cpp b/src/native/windows/juce_win32_PlatformUtils.cpp index 0e52a44dc0..e9682662cf 100644 --- a/src/native/windows/juce_win32_PlatformUtils.cpp +++ b/src/native/windows/juce_win32_PlatformUtils.cpp @@ -172,9 +172,7 @@ void PlatformUtilities::registerFileAssociation (const String& fileExtension, targetExecutable.getFullPathName() + "," + String (-iconResourceNumber)); setRegistryValue (key + "\\", fullDescription); - - setRegistryValue (key + "\\shell\\open\\command\\", - targetExecutable.getFullPathName() + " %1"); + setRegistryValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " %1"); } @@ -194,12 +192,10 @@ bool juce_IsRunningInWine() //============================================================================== const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() { - String s (::GetCommandLineW()); - - StringArray tokens; - tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument - - return tokens.joinIntoString (" ", 1); + const String commandLine (GetCommandLineW()); + return String (CharacterFunctions::findEndOfToken (commandLine.getCharPointer(), + String (" ").getCharPointer(), + String ("\"").getCharPointer())).trimStart(); } //============================================================================== diff --git a/src/text/juce_CharacterFunctions.h b/src/text/juce_CharacterFunctions.h index 2b8ccb61ad..ed5ad85869 100644 --- a/src/text/juce_CharacterFunctions.h +++ b/src/text/juce_CharacterFunctions.h @@ -500,6 +500,34 @@ public: return p; } + template + static Type findEndOfToken (const Type& text, const Type& breakCharacters, const Type& quoteCharacters) + { + Type t (text); + juce_wchar currentQuoteChar = 0; + + while (! t.isEmpty()) + { + const juce_wchar c = t.getAndAdvance(); + + if (currentQuoteChar == 0 && breakCharacters.indexOf (c) >= 0) + { + --t; + break; + } + + if (quoteCharacters.indexOf (c) >= 0) + { + if (currentQuoteChar == 0) + currentQuoteChar = c; + else if (currentQuoteChar == c) + currentQuoteChar = 0; + } + } + + return t; + } + private: static double mulexp10 (const double value, int exponent) throw(); }; diff --git a/src/text/juce_StringArray.cpp b/src/text/juce_StringArray.cpp index a05d1147de..274bfe2be2 100644 --- a/src/text/juce_StringArray.cpp +++ b/src/text/juce_StringArray.cpp @@ -354,48 +354,25 @@ int StringArray::addTokens (const String& text, const String& breakCharacters, c if (text.isNotEmpty()) { - bool insideQuotes = false; - juce_wchar currentQuoteChar = 0; - String::CharPointerType t (text.getCharPointer()); - String::CharPointerType tokenStart (t); - int numChars = 0; for (;;) { - const juce_wchar c = t.getAndAdvance(); - ++numChars; + String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t, + breakCharacters.getCharPointer(), + quoteCharacters.getCharPointer())); - const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c)); + if (tokenEnd == t) + break; - if (! isBreak) - { - if (quoteCharacters.containsChar (c)) - { - if (insideQuotes) - { - // only break out of quotes-mode if we find a matching quote to the - // one that we opened with.. - if (currentQuoteChar == c) - insideQuotes = false; - } - else - { - insideQuotes = true; - currentQuoteChar = c; - } - } - } - else - { - add (String (tokenStart, numChars - 1)); - ++num; - tokenStart = t; - numChars = 0; - } + add (String (t, tokenEnd)); + ++num; + t = tokenEnd; - if (c == 0) + if (t.isEmpty()) break; + + ++t; } }