operator >> wxString eat word by default. \n Add wxTextInputStream::Get/SetStringSeparator.\n Add wxTextInputStream::wxTextInputStream(wxInputStream, const wxChar &sep=' ')

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4241 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Sylvain Bougnoux
1999-10-28 12:33:55 +00:00
parent 87b501f0f7
commit 9853d97739
2 changed files with 68 additions and 9 deletions

View File

@@ -30,17 +30,22 @@ WXDLLEXPORT wxTextOutputStream &endl( wxTextOutputStream &stream );
class WXDLLEXPORT wxTextInputStream { class WXDLLEXPORT wxTextInputStream {
public: public:
wxTextInputStream(wxInputStream& s); wxTextInputStream(wxInputStream& s, const wxChar &sep=wxT(' '));
~wxTextInputStream(); ~wxTextInputStream();
wxUint32 Read32(); wxUint32 Read32();
wxUint16 Read16(); wxUint16 Read16();
wxUint8 Read8(); wxUint8 Read8();
double ReadDouble(); double ReadDouble();
wxString ReadString(); wxString ReadString(); // deprecated use ReadLine or ReadWord instead
wxString ReadLine();
wxString ReadWord();
wxChar GetStringSeparator() const { return m_string_separator;}
void SetStringSeparator(const wxChar &c) { m_string_separator=c;}
// Operators // Operators
wxTextInputStream& operator>>(wxString& line); wxTextInputStream& operator>>(wxString& word);
wxTextInputStream& operator>>(wxChar& c); wxTextInputStream& operator>>(wxChar& c);
wxTextInputStream& operator>>(wxInt16& i); wxTextInputStream& operator>>(wxInt16& i);
wxTextInputStream& operator>>(wxInt32& i); wxTextInputStream& operator>>(wxInt32& i);
@@ -53,6 +58,7 @@ public:
protected: protected:
wxInputStream *m_input; wxInputStream *m_input;
wxChar m_string_separator;
wxChar NextNonWhiteSpace(); wxChar NextNonWhiteSpace();
void SkipIfEndOfLine( wxChar c ); void SkipIfEndOfLine( wxChar c );

View File

@@ -38,8 +38,8 @@
// wxTextInputStream // wxTextInputStream
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxTextInputStream::wxTextInputStream(wxInputStream& s) wxTextInputStream::wxTextInputStream(wxInputStream& s, const wxChar &sep)
: m_input(&s) : m_input(&s), m_string_separator(sep)
{ {
} }
@@ -236,6 +236,11 @@ double wxTextInputStream::ReadDouble()
} }
wxString wxTextInputStream::ReadString() wxString wxTextInputStream::ReadString()
{
return ReadLine();
}
wxString wxTextInputStream::ReadLine()
{ {
wxChar c; wxChar c;
wxString line; wxString line;
@@ -277,9 +282,57 @@ wxString wxTextInputStream::ReadString()
return line; return line;
} }
wxTextInputStream& wxTextInputStream::operator>>(wxString& line) wxString wxTextInputStream::ReadWord()
{ {
line = ReadString(); wxChar c;
wxString word;
if (m_string_separator==wxT(' ')) c=NextNonWhiteSpace();
else c = m_input->GetC();
for (;;)
{
if (!m_input) break;
if (c == m_string_separator)
break;
if (c == wxT('\n'))
{
// eat on UNIX
break;
}
if (c == wxT('\r'))
{
// eat on both Mac and DOS
wxChar c2 = m_input->GetC();
if (!m_input) break;
if (c2 == wxT('\n'))
{
// eat on DOS
break;
}
else
{
// Don't eat on Mac
m_input->Ungetch( c2 );
break;
}
}
word += c;
c = m_input->GetC();
}
return word;
}
wxTextInputStream& wxTextInputStream::operator>>(wxString& word)
{
word = ReadWord();
return *this; return *this;
} }