From 93e4236b57f97f911ba35f665da9bb285b408aae Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Mon, 16 Nov 2009 18:12:17 +0000 Subject: [PATCH] Changes for VC6 compatibility; added a couple of trimming methods to String; added a parameter to Socket::createConnection --- juce_amalgamated.cpp | 54 ++++++++++++++++--- juce_amalgamated.h | 30 +++++++++-- .../code_editor/juce_CodeDocument.cpp | 11 ++-- .../code_editor/juce_CodeDocument.h | 7 +-- src/gui/graphics/contexts/juce_Graphics.cpp | 1 - .../contexts/juce_LowLevelGraphicsContext.h | 1 - ...uce_LowLevelGraphicsPostScriptRenderer.cpp | 1 - src/gui/graphics/geometry/juce_Path.cpp | 2 +- src/io/network/juce_Socket.cpp | 6 ++- src/io/network/juce_Socket.h | 7 ++- .../juce_win32_QuickTimeMovieComponent.cpp | 2 +- src/text/juce_String.cpp | 33 ++++++++++++ src/text/juce_String.h | 16 ++++++ 13 files changed, 142 insertions(+), 29 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 99a50a279f..36fa656da1 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -7753,7 +7753,7 @@ void StreamingSocket::close() isListener = false; } -bool StreamingSocket::createListener (const int newPortNumber) +bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName) { if (connected) close(); @@ -7766,6 +7766,10 @@ bool StreamingSocket::createListener (const int newPortNumber) zerostruct (servTmpAddr); servTmpAddr.sin_family = PF_INET; servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); + + if (localHostName.isNotEmpty()) + servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8()); + servTmpAddr.sin_port = htons ((uint16) portNumber); handle = (int) socket (AF_INET, SOCK_STREAM, 0); @@ -12133,6 +12137,39 @@ const String String::trimEnd() const throw() return String (text->text, (int) (++endT - text->text)); } +const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw() +{ + jassert (charactersToTrim != 0); + + if (isEmpty()) + return empty; + + const tchar* t = text->text; + + while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0) + ++t; + + if (t == text->text) + return *this; + else + return String (t); +} + +const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw() +{ + jassert (charactersToTrim != 0); + + if (isEmpty()) + return empty; + + const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1); + + while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0) + --endT; + + return String (text->text, (int) (++endT - text->text)); +} + const String String::retainCharacters (const tchar* const charactersToRetain) const throw() { jassert (charactersToRetain != 0); @@ -44035,8 +44072,8 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u lastAffectedLine = lines.size(); } - int lineStart = newFirstLine->lineStartInFile; - for (int i = firstAffectedLine; i < lines.size(); ++i) + int i, lineStart = newFirstLine->lineStartInFile; + for (i = firstAffectedLine; i < lines.size(); ++i) { CodeDocumentLine* const l = lines.getUnchecked (i); l->lineStartInFile = lineStart; @@ -44044,7 +44081,7 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u } const int newTextLength = text.length(); - for (int i = 0; i < positionsToMaintain.size(); ++i) + for (i = 0; i < positionsToMaintain.size(); ++i) { CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i); @@ -44135,7 +44172,8 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo lines.removeRange (firstAffectedLine + 1, numLinesToRemove); } - for (int i = firstAffectedLine + 1; i < lines.size(); ++i) + int i; + for (i = firstAffectedLine + 1; i < lines.size(); ++i) { CodeDocumentLine* const l = lines.getUnchecked (i); const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1); @@ -44144,7 +44182,7 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo const int totalChars = getNumCharacters(); - for (int i = 0; i < positionsToMaintain.size(); ++i) + for (i = 0; i < positionsToMaintain.size(); ++i) { CodeDocument::Position* p = positionsToMaintain.getUnchecked(i); @@ -90215,7 +90253,7 @@ Image* Path::createMaskBitmap (const AffineTransform& transform, Image* im = Image::createNativeImage (Image::SingleChannel, imagePosition.getWidth(), imagePosition.getHeight(), true); EdgeTable edgeTable (Rectangle (0, 0, imagePosition.getWidth(), imagePosition.getHeight()), - *this, transform.translated (-imagePosition.getX(), -imagePosition.getY())); + *this, transform.translated ((float) -imagePosition.getX(), (float) -imagePosition.getY())); int stride, pixelStride; uint8* const pixels = (uint8*) im->lockPixelDataReadWrite (0, 0, imagePosition.getWidth(), imagePosition.getHeight(), stride, pixelStride); @@ -242079,7 +242117,7 @@ bool QuickTimeMovieComponent::loadMovie (const File& movieFile_, bool QuickTimeMovieComponent::loadMovie (const URL& movieURL, const bool isControllerVisible) { - return loadMovie ((InputStream*) movieURL_.createInputStream (false), isControllerVisible); + return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible); } void QuickTimeMovieComponent::goToStart() diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 71b3aeffc8..430b594685 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -1994,6 +1994,22 @@ public: /** Returns a copy of this string with any whitespace characters removed from the end. */ const String trimEnd() const throw(); + /** Returns a copy of this string, having removed a specified set of characters from its start. + Characters are removed from the start of the string until it finds one that is not in the + specified set, and then it stops. + @param charactersToTrim the set of characters to remove. This must not be null. + @see trim, trimStart, trimCharactersAtEnd + */ + const String trimCharactersAtStart (const tchar* charactersToTrim) const throw(); + + /** Returns a copy of this string, having removed a specified set of characters from its end. + Characters are removed from the end of the string until it finds one that is not in the + specified set, and then it stops. + @param charactersToTrim the set of characters to remove. This must not be null. + @see trim, trimEnd, trimCharactersAtStart + */ + const String trimCharactersAtEnd (const tchar* charactersToTrim) const throw(); + /** Returns an upper-case version of this string. */ const String toUpperCase() const throw(); @@ -13063,11 +13079,14 @@ public: which will spawn new sockets for each new connection, so that these can be handled in parallel by other threads. - This returns true if it manages to open the socket successfully. + @param portNumber the port number to listen on + @param localHostName the interface address to listen on - pass an empty + string to listen on all addresses + @returns true if it manages to open the socket successfully. @see waitForNextConnection */ - bool createListener (const int portNumber); + bool createListener (const int portNumber, const String& localHostName = String::empty); /** When in "listener" mode, this waits for a connection and spawns it as a new socket. @@ -44635,8 +44654,8 @@ public: /** Called by a CodeDocument when it is altered. */ - virtual void codeDocumentChanged (const CodeDocument::Position& affectedTextStart, - const CodeDocument::Position& affectedTextEnd) = 0; + virtual void codeDocumentChanged (const Position& affectedTextStart, + const Position& affectedTextEnd) = 0; }; /** Registers a listener object to receive callbacks when the document changes. @@ -44703,7 +44722,8 @@ public: private: friend class CodeDocumentInsertAction; friend class CodeDocumentDeleteAction; - friend class CodeDocument::Iterator; + friend class Iterator; + friend class Position; OwnedArray lines; Array positionsToMaintain; diff --git a/src/gui/components/code_editor/juce_CodeDocument.cpp b/src/gui/components/code_editor/juce_CodeDocument.cpp index 03aa8820e6..2e58e75efe 100644 --- a/src/gui/components/code_editor/juce_CodeDocument.cpp +++ b/src/gui/components/code_editor/juce_CodeDocument.cpp @@ -778,8 +778,8 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u lastAffectedLine = lines.size(); } - int lineStart = newFirstLine->lineStartInFile; - for (int i = firstAffectedLine; i < lines.size(); ++i) + int i, lineStart = newFirstLine->lineStartInFile; + for (i = firstAffectedLine; i < lines.size(); ++i) { CodeDocumentLine* const l = lines.getUnchecked (i); l->lineStartInFile = lineStart; @@ -787,7 +787,7 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u } const int newTextLength = text.length(); - for (int i = 0; i < positionsToMaintain.size(); ++i) + for (i = 0; i < positionsToMaintain.size(); ++i) { CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i); @@ -879,7 +879,8 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo lines.removeRange (firstAffectedLine + 1, numLinesToRemove); } - for (int i = firstAffectedLine + 1; i < lines.size(); ++i) + int i; + for (i = firstAffectedLine + 1; i < lines.size(); ++i) { CodeDocumentLine* const l = lines.getUnchecked (i); const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1); @@ -888,7 +889,7 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo const int totalChars = getNumCharacters(); - for (int i = 0; i < positionsToMaintain.size(); ++i) + for (i = 0; i < positionsToMaintain.size(); ++i) { CodeDocument::Position* p = positionsToMaintain.getUnchecked(i); diff --git a/src/gui/components/code_editor/juce_CodeDocument.h b/src/gui/components/code_editor/juce_CodeDocument.h index abde03dfc4..f849d63431 100644 --- a/src/gui/components/code_editor/juce_CodeDocument.h +++ b/src/gui/components/code_editor/juce_CodeDocument.h @@ -302,8 +302,8 @@ public: /** Called by a CodeDocument when it is altered. */ - virtual void codeDocumentChanged (const CodeDocument::Position& affectedTextStart, - const CodeDocument::Position& affectedTextEnd) = 0; + virtual void codeDocumentChanged (const Position& affectedTextStart, + const Position& affectedTextEnd) = 0; }; /** Registers a listener object to receive callbacks when the document changes. @@ -372,7 +372,8 @@ public: private: friend class CodeDocumentInsertAction; friend class CodeDocumentDeleteAction; - friend class CodeDocument::Iterator; + friend class Iterator; + friend class Position; OwnedArray lines; Array positionsToMaintain; diff --git a/src/gui/graphics/contexts/juce_Graphics.cpp b/src/gui/graphics/contexts/juce_Graphics.cpp index a09caaeb07..251461de60 100644 --- a/src/gui/graphics/contexts/juce_Graphics.cpp +++ b/src/gui/graphics/contexts/juce_Graphics.cpp @@ -30,7 +30,6 @@ BEGIN_JUCE_NAMESPACE #include "juce_Graphics.h" #include "../fonts/juce_GlyphArrangement.h" #include "../geometry/juce_PathStrokeType.h" -#include "juce_EdgeTable.h" #include "juce_LowLevelGraphicsContext.h" #include "../brushes/juce_GradientBrush.h" #include "../brushes/juce_ImageBrush.h" diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h b/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h index 6e83f6d7e2..a350b11649 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h @@ -30,7 +30,6 @@ #include "../geometry/juce_Path.h" #include "../geometry/juce_RectangleList.h" #include "../colour/juce_ColourGradient.h" -#include "juce_EdgeTable.h" //============================================================================== diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp index c8dc9dfaa8..6f3c3f39ff 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp @@ -28,7 +28,6 @@ BEGIN_JUCE_NAMESPACE #include "juce_LowLevelGraphicsPostScriptRenderer.h" -#include "juce_EdgeTable.h" #include "../imaging/juce_Image.h" #include "../colour/juce_PixelFormats.h" #include "../geometry/juce_PathStrokeType.h" diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index e9391ea0a5..df5c31dd23 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -1604,7 +1604,7 @@ Image* Path::createMaskBitmap (const AffineTransform& transform, Image* im = Image::createNativeImage (Image::SingleChannel, imagePosition.getWidth(), imagePosition.getHeight(), true); EdgeTable edgeTable (Rectangle (0, 0, imagePosition.getWidth(), imagePosition.getHeight()), - *this, transform.translated (-imagePosition.getX(), -imagePosition.getY())); + *this, transform.translated ((float) -imagePosition.getX(), (float) -imagePosition.getY())); int stride, pixelStride; uint8* const pixels = (uint8*) im->lockPixelDataReadWrite (0, 0, imagePosition.getWidth(), imagePosition.getHeight(), stride, pixelStride); diff --git a/src/io/network/juce_Socket.cpp b/src/io/network/juce_Socket.cpp index b4fe4f3547..3af0257d37 100644 --- a/src/io/network/juce_Socket.cpp +++ b/src/io/network/juce_Socket.cpp @@ -429,7 +429,7 @@ void StreamingSocket::close() } //============================================================================== -bool StreamingSocket::createListener (const int newPortNumber) +bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName) { if (connected) close(); @@ -442,6 +442,10 @@ bool StreamingSocket::createListener (const int newPortNumber) zerostruct (servTmpAddr); servTmpAddr.sin_family = PF_INET; servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); + + if (localHostName.isNotEmpty()) + servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8()); + servTmpAddr.sin_port = htons ((uint16) portNumber); handle = (int) socket (AF_INET, SOCK_STREAM, 0); diff --git a/src/io/network/juce_Socket.h b/src/io/network/juce_Socket.h index 45eb46f5ab..81ee5f8519 100644 --- a/src/io/network/juce_Socket.h +++ b/src/io/network/juce_Socket.h @@ -135,11 +135,14 @@ public: which will spawn new sockets for each new connection, so that these can be handled in parallel by other threads. - This returns true if it manages to open the socket successfully. + @param portNumber the port number to listen on + @param localHostName the interface address to listen on - pass an empty + string to listen on all addresses + @returns true if it manages to open the socket successfully. @see waitForNextConnection */ - bool createListener (const int portNumber); + bool createListener (const int portNumber, const String& localHostName = String::empty); /** When in "listener" mode, this waits for a connection and spawns it as a new socket. diff --git a/src/native/windows/juce_win32_QuickTimeMovieComponent.cpp b/src/native/windows/juce_win32_QuickTimeMovieComponent.cpp index b1b4f1b815..ba5bf4b434 100644 --- a/src/native/windows/juce_win32_QuickTimeMovieComponent.cpp +++ b/src/native/windows/juce_win32_QuickTimeMovieComponent.cpp @@ -477,7 +477,7 @@ bool QuickTimeMovieComponent::loadMovie (const File& movieFile_, bool QuickTimeMovieComponent::loadMovie (const URL& movieURL, const bool isControllerVisible) { - return loadMovie ((InputStream*) movieURL_.createInputStream (false), isControllerVisible); + return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible); } void QuickTimeMovieComponent::goToStart() diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index 52ac77be27..8ec15dcf4f 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -1748,6 +1748,39 @@ const String String::trimEnd() const throw() return String (text->text, (int) (++endT - text->text)); } +const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw() +{ + jassert (charactersToTrim != 0); + + if (isEmpty()) + return empty; + + const tchar* t = text->text; + + while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0) + ++t; + + if (t == text->text) + return *this; + else + return String (t); +} + +const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw() +{ + jassert (charactersToTrim != 0); + + if (isEmpty()) + return empty; + + const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1); + + while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0) + --endT; + + return String (text->text, (int) (++endT - text->text)); +} + //============================================================================== const String String::retainCharacters (const tchar* const charactersToRetain) const throw() { diff --git a/src/text/juce_String.h b/src/text/juce_String.h index f0e363766a..65d077c8db 100644 --- a/src/text/juce_String.h +++ b/src/text/juce_String.h @@ -613,6 +613,22 @@ public: /** Returns a copy of this string with any whitespace characters removed from the end. */ const String trimEnd() const throw(); + /** Returns a copy of this string, having removed a specified set of characters from its start. + Characters are removed from the start of the string until it finds one that is not in the + specified set, and then it stops. + @param charactersToTrim the set of characters to remove. This must not be null. + @see trim, trimStart, trimCharactersAtEnd + */ + const String trimCharactersAtStart (const tchar* charactersToTrim) const throw(); + + /** Returns a copy of this string, having removed a specified set of characters from its end. + Characters are removed from the end of the string until it finds one that is not in the + specified set, and then it stops. + @param charactersToTrim the set of characters to remove. This must not be null. + @see trim, trimEnd, trimCharactersAtStart + */ + const String trimCharactersAtEnd (const tchar* charactersToTrim) const throw(); + //============================================================================== /** Returns an upper-case version of this string. */ const String toUpperCase() const throw();