diff --git a/include/wx/datstrm.h b/include/wx/datstrm.h index e0c4bfe7ff..40537e3291 100644 --- a/include/wx/datstrm.h +++ b/include/wx/datstrm.h @@ -29,7 +29,6 @@ public: wxUint16 Read16(); wxUint8 Read8(); double ReadDouble(); - wxString ReadLine(); wxString ReadString(); }; @@ -42,7 +41,6 @@ class WXDLLEXPORT wxDataOutputStream: public wxFilterOutputStream { void Write16(wxUint16 i); void Write8(wxUint8 i); void WriteDouble(double d); - void WriteLine(const wxString& line); void WriteString(const wxString& string); }; diff --git a/include/wx/stream.h b/include/wx/stream.h index b5920ea8ce..508ca1a258 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -161,6 +161,7 @@ class WXDLLEXPORT wxInputStream: public wxStreamBase { char GetC(); virtual wxInputStream& Read(void *buffer, size_t size); wxInputStream& Read(wxOutputStream& stream_out); + wxString ReadLine(); // Position functions off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart); @@ -201,6 +202,7 @@ class WXDLLEXPORT wxOutputStream: public wxStreamBase { virtual wxOutputStream& Write(const void *buffer, size_t size); wxOutputStream& Write(wxInputStream& stream_in); + void WriteLine(const wxString& line); off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart); off_t TellO() const; diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index cab308f18e..771d9c32d2 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -82,37 +82,6 @@ double wxDataInputStream::ReadDouble() #endif } -wxString wxDataInputStream::ReadLine() -{ - char c, last_endl = 0; - bool end_line = FALSE; - wxString line; - - while (!end_line) { - c = GetC(); - if (LastError() != wxStream_NOERROR) - break; - - switch (c) { - case '\n': - end_line = TRUE; - break; - case '\r': - last_endl = '\r'; - break; - default: - if (last_endl == '\r') { - end_line = TRUE; - InputStreamBuffer()->WriteBack(c); - break; - } - line += c; - break; - } - } - return line; -} - wxString wxDataInputStream::ReadString() { wxString wx_string; @@ -169,17 +138,6 @@ void wxDataOutputStream::Write8(wxUint8 i) Write(&i, 1); } -void wxDataOutputStream::WriteLine(const wxString& line) -{ -#ifdef __WXMSW__ - wxString tmp_string = line + _T("\r\n"); -#else - wxString tmp_string = line + _T('\n'); -#endif - - Write((const wxChar *) tmp_string, tmp_string.Length()*sizeof(wxChar)); -} - void wxDataOutputStream::WriteString(const wxString& string) { Write32(string.Length()); diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 9750fef812..4d32e503ea 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -549,6 +549,38 @@ char wxInputStream::GetC() return c; } + +wxString wxInputStream::ReadLine() +{ + char c, last_endl = 0; + bool end_line = FALSE; + wxString line; + + while (!end_line) { + c = GetC(); + if (LastError() != wxStream_NOERROR) + break; + + switch (c) { + case '\n': + end_line = TRUE; + break; + case '\r': + last_endl = '\r'; + break; + default: + if (last_endl == '\r') { + end_line = TRUE; + InputStreamBuffer()->WriteBack(c); + break; + } + line += c; + break; + } + } + return line; +} + wxInputStream& wxInputStream::Read(void *buffer, size_t size) { m_i_streambuf->Read(buffer, size); @@ -592,9 +624,7 @@ off_t wxInputStream::TellI() const wxInputStream& wxInputStream::operator>>(wxString& line) { - wxDataInputStream s(*this); - - line = s.ReadLine(); + line = ReadLine(); return *this; } @@ -802,6 +832,21 @@ void wxOutputStream::Sync() m_o_streambuf->FlushBuffer(); } +void wxOutputStream::WriteLine(const wxString& line) +{ +#ifdef __WXMSW__ + wxString tmp_string = line + _T("\r\n"); +#else +#ifdef __WXMAC__ + wxString tmp_string = line + _T('\r'); +#else + wxString tmp_string = line + _T('\n'); +#endif +#endif + + Write((const wxChar *) tmp_string, tmp_string.Length()*sizeof(wxChar)); +} + wxOutputStream& wxOutputStream::operator<<(const char *string) { return Write(string, strlen(string)); @@ -922,9 +967,13 @@ wxOutputStream& wxEndL(wxOutputStream& stream) { #ifdef __MSW__ return stream.Write("\r\n", 2); +#else +#ifdef __WXMAC__ + return stream.Write("\r", 1); #else return stream.Write("\n", 1); #endif +#endif } #endif