Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

asstreamiterator.cpp

/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * $Revision$
 * $Id$
 * $HeadURL$
 */

#include "asstreamiterator.h"
#include "globals.h"

ASStreamIterator::ASStreamIterator(cbEditor *cbe, const wxChar* in)
: m_cbe(cbe), m_In(in), m_curline(0), m_foundBookmark(false)
{
      //ctor
}

ASStreamIterator::~ASStreamIterator()
{
      //dtor
}

bool ASStreamIterator::hasMoreLines() const
{
    return (*m_In) != 0;
}

inline bool ASStreamIterator::IsEOL(wxChar ch)
{
  if (ch == _T('\r') || ch == _T('\n'))
  {
      return true;
  }

  return false;
}

std::string ASStreamIterator::nextLine()
{
  // 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;
  }

  m_buffer.clear();

  while (*m_In != 0)
  {
    if (!IsEOL(*m_In))
    {
      m_buffer.push_back(*m_In);
    }

    ++m_In;

    if (IsEOL(*m_In))
    {
      // if CRLF (two chars) peek next char (avoid duplicating empty-lines)
      if (*m_In != *(m_In + 1) && IsEOL(*(m_In + 1)))
      {
        ++m_In;
      }

      break;
    }
  }

  m_buffer.push_back(0);
  ++m_curline;

  return std::string(cbU2C(&m_buffer[0]));
}

Generated by  Doxygen 1.6.0   Back to index