]> git.saurik.com Git - wxWidgets.git/commitdiff
operator >> wxString eat word by default. \n Add wxTextInputStream::Get/SetStringSepa...
authorSylvain Bougnoux <bougnoux@imra-europe.com>
Thu, 28 Oct 1999 12:33:55 +0000 (12:33 +0000)
committerSylvain Bougnoux <bougnoux@imra-europe.com>
Thu, 28 Oct 1999 12:33:55 +0000 (12:33 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4241 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/txtstrm.h
src/common/txtstrm.cpp

index afa18e3bce7a95364247873b6d4cb357fb26e434..2b3b897f20afa6e1d8bc01a29895251d1f95f878 100644 (file)
@@ -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 );
index 2dfa95ff8f489b3b5dacf337ef2fbdf212dda230..3cb2c5bb5fe88f2a166c5940b9ee69ec27fa38c4 100644 (file)
@@ -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()
+{
+    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)
 {
-  line = ReadString();
+  word = ReadWord();
   return *this;
 }