1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-24 01:54:22 +00:00

Reduced the memory footprint of the array classes.

This commit is contained in:
Julian Storer 2010-02-06 09:16:20 +00:00
parent ded4826413
commit 31a102008d
11 changed files with 542 additions and 489 deletions

View file

@ -532,6 +532,28 @@ void CodeDocument::replaceAllContent (const String& newContent)
insert (newContent, 0, true);
}
bool CodeDocument::loadFromStream (InputStream& stream)
{
replaceAllContent (stream.readEntireStreamAsString());
setSavePoint();
clearUndoHistory();
return true;
}
bool CodeDocument::writeToStream (OutputStream& stream)
{
for (int i = 0; i < lines.size(); ++i)
{
String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
const char* utf8 = temp.toUTF8();
if (! stream.write (utf8, strlen (utf8)))
return false;
}
return true;
}
void CodeDocument::setNewLineCharacters (const String& newLine) throw()
{
jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));

View file

@ -29,6 +29,8 @@
#include "../../../utilities/juce_UndoManager.h"
#include "../../graphics/colour/juce_Colour.h"
#include "../../../containers/juce_VoidArray.h"
#include "../../../io/streams/juce_InputStream.h"
#include "../../../io/streams/juce_OutputStream.h"
class CodeDocumentLine;
@ -225,6 +227,14 @@ public:
*/
void replaceAllContent (const String& newContent);
/** Replaces the editor's contents with the contents of a stream.
This will also reset the undo history and save point marker.
*/
bool loadFromStream (InputStream& stream);
/** Writes the editor's current contents to a stream. */
bool writeToStream (OutputStream& stream);
//==============================================================================
/** Returns the preferred new-line characters for the document.
This will be either "\n", "\r\n", or (rarely) "\r".