Skip to content

Commit f5ba405

Browse files
committed
r27 | charles.nicholson | 2010-03-25 15:45:52 -0500 (Thu, 25 Mar 2010) | 1 line
add Clear() to MemoryOutStream()
1 parent 3fe7f2f commit f5ba405

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/MemoryOutStream.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ char const* MemoryOutStream::GetText() const
1010
return m_text.c_str();
1111
}
1212

13+
void MemoryOutStream::Clear()
14+
{
15+
this->str(std::string());
16+
m_text = this->str();
17+
}
18+
1319
}
1420

1521
#else
@@ -52,6 +58,11 @@ MemoryOutStream::~MemoryOutStream()
5258
delete [] m_buffer;
5359
}
5460

61+
void MemoryOutStream::Clear()
62+
{
63+
m_buffer[0] = '\0';
64+
}
65+
5566
char const* MemoryOutStream::GetText() const
5667
{
5768
return m_buffer;

src/MemoryOutStream.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream
1616
public:
1717
MemoryOutStream() {}
1818
~MemoryOutStream() {}
19-
char const* GetText() const;
19+
void Clear();
20+
char const* GetText() const;
2021

2122
private:
2223
MemoryOutStream(MemoryOutStream const&);
@@ -40,6 +41,7 @@ class UNITTEST_LINKAGE MemoryOutStream
4041
explicit MemoryOutStream(int const size = 256);
4142
~MemoryOutStream();
4243

44+
void Clear();
4345
char const* GetText() const;
4446

4547
MemoryOutStream& operator <<(char const* txt);

src/tests/TestMemoryOutStream.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ TEST(StreamingSizeTWritesCorrectCharacters)
103103
CHECK_EQUAL("53124", stream.GetText());
104104
}
105105

106+
TEST(ClearEmptiesMemoryOutStreamContents)
107+
{
108+
MemoryOutStream stream;
109+
stream << "Hello world";
110+
stream.Clear();
111+
CHECK_EQUAL("", stream.GetText());
112+
}
113+
106114
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
107115

108116
TEST(StreamInitialCapacityIsCorrect)

0 commit comments

Comments
 (0)