Browse Source

Fix plStringStream for the case of adding a '\0' char non-destructively

Michael Hansen 13 years ago committed by Adam Johnson
parent
commit
8bf78c0e35
  1. 17
      Sources/Plasma/CoreLib/plString.cpp
  2. 6
      Sources/Plasma/CoreLib/plString.h

17
Sources/Plasma/CoreLib/plString.cpp

@ -699,9 +699,8 @@ plString operator+(const plString &left, const plString &right)
return str;
}
plStringStream &plStringStream::operator<<(const char *text)
plStringStream &plStringStream::append(const char *data, size_t length)
{
size_t length = strlen(text);
if (fLength + length > fBufSize) {
char *bigger = new char[fBufSize * 2];
memcpy(bigger, fBuffer, fBufSize);
@ -709,11 +708,17 @@ plStringStream &plStringStream::operator<<(const char *text)
fBuffer = bigger;
fBufSize *= 2;
}
memcpy(fBuffer + fLength, text, length);
memcpy(fBuffer + fLength, data, length);
fLength += length;
return *this;
}
plStringStream &plStringStream::operator<<(const char *text)
{
size_t length = strlen(text);
return append(text, length);
}
plStringStream &plStringStream::operator<<(int num)
{
char buffer[12];
@ -727,9 +732,3 @@ plStringStream &plStringStream::operator<<(unsigned int num)
snprintf(buffer, 12, "%u", num);
return operator<<(buffer);
}
plStringStream &plStringStream::operator<<(char ch)
{
char buffer[2] = { ch, 0 };
return operator<<(buffer);
}

6
Sources/Plasma/CoreLib/plString.h

@ -408,14 +408,16 @@ public:
}
~plStringStream() { delete [] fBuffer; }
plStringStream &append(const char *data, size_t length);
plStringStream &operator<<(const char *text);
plStringStream &operator<<(int num);
plStringStream &operator<<(unsigned int num);
plStringStream &operator<<(char ch);
plStringStream &operator<<(char ch) { return append(&ch, 1); }
plStringStream &operator<<(const plString &text)
{
return operator<<(text.s_str());
return append(text.s_str(), text.GetSize());
}
size_t GetLength() const { return fLength; }

Loading…
Cancel
Save