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:
parent
87b501f0f7
commit
9853d97739
@ -30,17 +30,22 @@ WXDLLEXPORT wxTextOutputStream &endl( wxTextOutputStream &stream );
|
||||
|
||||
class WXDLLEXPORT wxTextInputStream {
|
||||
public:
|
||||
wxTextInputStream(wxInputStream& s);
|
||||
wxTextInputStream(wxInputStream& s, const wxChar &sep=wxT(' '));
|
||||
~wxTextInputStream();
|
||||
|
||||
wxUint32 Read32();
|
||||
wxUint16 Read16();
|
||||
wxUint8 Read8();
|
||||
double ReadDouble();
|
||||
wxString ReadString();
|
||||
wxUint8 Read8();
|
||||
double ReadDouble();
|
||||
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
|
||||
wxTextInputStream& operator>>(wxString& line);
|
||||
wxTextInputStream& operator>>(wxString& word);
|
||||
wxTextInputStream& operator>>(wxChar& c);
|
||||
wxTextInputStream& operator>>(wxInt16& i);
|
||||
wxTextInputStream& operator>>(wxInt32& i);
|
||||
@ -53,6 +58,7 @@ public:
|
||||
|
||||
protected:
|
||||
wxInputStream *m_input;
|
||||
wxChar m_string_separator;
|
||||
|
||||
wxChar NextNonWhiteSpace();
|
||||
void SkipIfEndOfLine( wxChar c );
|
||||
|
@ -38,8 +38,8 @@
|
||||
// wxTextInputStream
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxTextInputStream::wxTextInputStream(wxInputStream& s)
|
||||
: m_input(&s)
|
||||
wxTextInputStream::wxTextInputStream(wxInputStream& s, const wxChar &sep)
|
||||
: m_input(&s), m_string_separator(sep)
|
||||
{
|
||||
}
|
||||
|
||||
@ -236,6 +236,11 @@ double wxTextInputStream::ReadDouble()
|
||||
}
|
||||
|
||||
wxString wxTextInputStream::ReadString()
|
||||
{
|
||||
return ReadLine();
|
||||
}
|
||||
|
||||
wxString wxTextInputStream::ReadLine()
|
||||
{
|
||||
wxChar c;
|
||||
wxString line;
|
||||
@ -277,9 +282,57 @@ wxString wxTextInputStream::ReadString()
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user