diff --git a/include/wx/txtstrm.h b/include/wx/txtstrm.h index 8fc43a176f..5218f44520 100644 --- a/include/wx/txtstrm.h +++ b/include/wx/txtstrm.h @@ -25,7 +25,8 @@ typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&); WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream ); -#define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream) +// Obsolete constant defined only for compatibility, not used. +#define wxEOT wxT('\4') // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_ // reading the next item (word / number), because otherwise the last item may get lost. @@ -58,7 +59,7 @@ public: double ReadDouble(); wxString ReadLine(); wxString ReadWord(); - wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); } + wxChar GetChar(); wxString GetStringSeparators() const { return m_separators; } void SetStringSeparators(const wxString &c) { m_separators = c; } @@ -100,8 +101,6 @@ protected: bool EatEOL(const wxChar &c); void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues - // returns EOT (\4) if there is a stream error, or end of file - wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues wxChar NextNonSeparators(); wxDECLARE_NO_COPY_CLASS(wxTextInputStream); diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp index 8c48cd6c77..86c19583b0 100644 --- a/src/common/txtstrm.cpp +++ b/src/common/txtstrm.cpp @@ -65,7 +65,7 @@ void wxTextInputStream::UngetLast() memset((void*)m_lastBytes, 0, 10); } -wxChar wxTextInputStream::NextChar() +wxChar wxTextInputStream::GetChar() { #if wxUSE_UNICODE #if SIZEOF_WCHAR_T == 2 @@ -87,7 +87,7 @@ wxChar wxTextInputStream::NextChar() m_lastBytes[inlen] = m_input.GetC(); if(m_input.LastRead() <= 0) - return wxEOT; + return 0; switch ( m_conv->ToWChar(wbuf, WXSIZEOF(wbuf), m_lastBytes, inlen + 1) ) { @@ -108,7 +108,7 @@ wxChar wxTextInputStream::NextChar() // them with an extra single byte, something fishy is going on // (except if we use UTF-16, see below) wxFAIL_MSG("unexpected decoding result"); - return wxEOT; + return 0; #if SIZEOF_WCHAR_T == 2 case 2: @@ -131,12 +131,12 @@ wxChar wxTextInputStream::NextChar() // there should be no encoding which requires more than nine bytes for one // character so something must be wrong with our conversion but we have no // way to signal it from here - return wxEOT; + return 0; #else m_lastBytes[0] = m_input.GetC(); if(m_input.LastRead() <= 0) - return wxEOT; + return 0; return m_lastBytes[0]; #endif @@ -147,8 +147,9 @@ wxChar wxTextInputStream::NextNonSeparators() { for (;;) { - wxChar c = NextChar(); - if (c == wxEOT) return (wxChar) 0; + wxChar c = GetChar(); + if (!c) + return c; if (c != wxT('\n') && c != wxT('\r') && @@ -164,8 +165,8 @@ bool wxTextInputStream::EatEOL(const wxChar &c) if (c == wxT('\r')) // eat on both Mac and DOS { - wxChar c2 = NextChar(); - if(c2 == wxEOT) return true; // end of stream reached, had enough :-) + wxChar c2 = GetChar(); + if (!c2) return true; // end of stream reached, had enough :-) if (c2 != wxT('\n')) UngetLast(); // Don't eat on Mac return true; @@ -261,8 +262,8 @@ wxString wxTextInputStream::ReadLine() while ( !m_input.Eof() ) { - wxChar c = NextChar(); - if(c == wxEOT) + wxChar c = GetChar(); + if (!c) break; if (EatEOL(c)) @@ -289,8 +290,8 @@ wxString wxTextInputStream::ReadWord() while ( !m_input.Eof() ) { - c = NextChar(); - if(c == wxEOT) + c = GetChar(); + if (!c) break; if (m_separators.Find(c) >= 0)