Blob Blame History Raw
diff --git a/src/plugins/astyle/asstreamiterator.cpp b/src/plugins/astyle/asstreamiterator.cpp
index 4bd394c..a2d75f2 100644
--- a/src/plugins/astyle/asstreamiterator.cpp
+++ b/src/plugins/astyle/asstreamiterator.cpp
@@ -8,93 +8,98 @@
  */
 
 #include "asstreamiterator.h"
+
+#include <vector>
+
+#include "cbstyledtextctrl.h"
 #include "globals.h"
 
-ASStreamIterator::ASStreamIterator(cbEditor *cbe, const wxChar* in)
-: m_cbe(cbe), m_In(in), m_PeekStart(0), m_curline(0), m_foundBookmark(false),
-m_foundBreakpoint(false)
+ASStreamIterator::ASStreamIterator(cbEditor* cbe, const wxChar* in) :
+  m_Ed(cbe),
+  m_CharPtr(in),
+  m_SavedCharPtr(0),
+  m_CurChar(0),
+  m_CurLine(0),
+  m_FoundBookmark(false),
+  m_FoundBreakpoint(false)
 {
-	//ctor
 }
 
 ASStreamIterator::~ASStreamIterator()
 {
-	//dtor
 }
 
 bool ASStreamIterator::hasMoreLines() const
 {
-    return (*m_In) != 0;
+    return (*m_CharPtr) != 0;
 }
 
-inline bool ASStreamIterator::IsEOL(wxChar ch)
+int ASStreamIterator::getStreamLength() const
 {
-    if (ch == _T('\r') || ch == _T('\n'))
-    {
-        return true;
-    }
-
-    return false;
+    return static_cast<int>(m_Ed->GetControl()->GetLength());
 }
 
 std::string ASStreamIterator::nextLine(cb_unused bool emptyLineWasDeleted)
 {
-    // hack: m_curline = 0 is a special case we should not evaluate here
-    if (m_cbe && m_curline && m_cbe->HasBookmark(m_curline))
-    {
-        m_foundBookmark = true;
-    }
-    if (m_cbe && m_curline && m_cbe->HasBreakpoint(m_curline))
-    {
-        m_foundBreakpoint = true;
-    }
+    // hack: m_CurLine = 0 is a special case we should not evaluate here
+    if (m_Ed && m_CurLine && m_Ed->HasBookmark(m_CurLine))
+        m_FoundBookmark = true;
+
+    if (m_Ed && m_CurLine && m_Ed->HasBreakpoint(m_CurLine))
+        m_FoundBreakpoint = true;
 
     return readLine();
 }
 
+std::string ASStreamIterator::peekNextLine()
+{
+    if (!m_SavedCharPtr)
+        m_SavedCharPtr = m_CharPtr;
+
+    return readLine();
+}
+
+void ASStreamIterator::peekReset()
+{
+    m_CharPtr = m_SavedCharPtr;
+    m_SavedCharPtr = 0;
+}
+
+std::streamoff ASStreamIterator::tellg()
+{
+    return static_cast<std::streamoff>(m_CurChar);
+}
+
+// private
+
 std::string ASStreamIterator::readLine()
 {
-    m_buffer.clear();
+    static std::vector<wxChar> buf;
+    buf.clear();
 
-    while (*m_In != 0)
+    while (*m_CharPtr != 0)
     {
-        if (!IsEOL(*m_In))
-        {
-            m_buffer.push_back(*m_In);
-        }
+        if ( !IsEOL(*m_CharPtr) )
+            buf.push_back(*m_CharPtr);
 
-        ++m_In;
+        ++m_CharPtr;
+        ++m_CurChar;
 
-        if (IsEOL(*m_In))
+        if ( IsEOL(*m_CharPtr) )
         {
             // if CRLF (two chars) peek next char (avoid duplicating empty-lines)
-            if (*m_In != *(m_In + 1) && IsEOL(*(m_In + 1)))
+            if (*m_CharPtr != *(m_CharPtr + 1) && IsEOL(*(m_CharPtr + 1)))
             {
-                ++m_In;
+                ++m_CharPtr;
+                ++m_CurChar;
             }
 
             break;
         }
     }
 
-    m_buffer.push_back(0);
-    ++m_curline;
+    buf.push_back(0);
+    ++m_CurLine;
 
-    return std::string(cbU2C(&m_buffer[0]));
-}
-
-std::string ASStreamIterator::peekNextLine()
-{
-    if (!m_PeekStart)
-    {
-        m_PeekStart = m_In;
-    }
-
-    return readLine();
-}
-
-void ASStreamIterator::peekReset()
-{
-    m_In = m_PeekStart;
-    m_PeekStart = 0;
+    return static_cast<std::string>( cbU2C(&buf[0]) );
 }
diff --git a/src/plugins/astyle/asstreamiterator.h b/src/plugins/astyle/asstreamiterator.h
index d30398d..f2061d8 100644
--- a/src/plugins/astyle/asstreamiterator.h
+++ b/src/plugins/astyle/asstreamiterator.h
@@ -7,35 +7,41 @@
 #define ASSTREAMITERATOR_H
 
 #include <iostream>
+
 #include <wx/string.h>
+
 #include <cbeditor.h>
-#include <vector>
+
 #include <astyle.h>
 
 class ASStreamIterator : public astyle::ASSourceIterator
 {
     public:
-        ASStreamIterator(cbEditor *cbe, const wxChar *in);
+        ASStreamIterator(cbEditor* cbe, const wxChar* in);
         virtual ~ASStreamIterator();
 
         bool hasMoreLines() const;
+        int  getStreamLength() const;
         std::string nextLine(bool emptyLineWasDeleted = false);
         std::string peekNextLine();
         void peekReset();
-        bool FoundBookmark() const { return m_foundBookmark; }
-        void ClearFoundBookmark() { m_foundBookmark = false; }
-        bool FoundBreakpoint() const { return m_foundBreakpoint; }
-        void ClearFoundBreakpoint() { m_foundBreakpoint = false; }
+        std::streamoff tellg();
+
+        bool FoundBookmark() const   { return m_FoundBookmark;    }
+        void ClearFoundBookmark()    { m_FoundBookmark = false;   }
+        bool FoundBreakpoint() const { return m_FoundBreakpoint;  }
+        void ClearFoundBreakpoint()  { m_FoundBreakpoint = false; }
 
     protected:
-        bool IsEOL(wxChar ch);
-        cbEditor *m_cbe;
-        const wxChar *m_In;
-        const wxChar *m_PeekStart;
-        std::vector<wxChar> m_buffer;
-        int m_curline;
-        bool m_foundBookmark;
-        bool m_foundBreakpoint;
+        inline bool IsEOL(wxChar ch) { return (ch == _T('\r') || ch == _T('\n')); }
+
+        cbEditor*           m_Ed;
+        const wxChar*       m_CharPtr;
+        const wxChar*       m_SavedCharPtr;
+        int                 m_CurChar;
+        int                 m_CurLine;
+        bool                m_FoundBookmark;
+        bool                m_FoundBreakpoint;
 
     private:
         std::string readLine();