#ifndef __ANSIPARSER_H__
#define __ANSIPARSER_H__
//-----------------------------------------------------------------------------
///
/// \brief  Ansi to HTML converter
///
///         see implementation for further information
///
/// \date   20150326
/// \author Maximilian Seesslen <development@seesslen.net>
///
//-----------------------------------------------------------------------------


//---Includes------------------------------------------------------------------


#if defined(STM32)
   #include <lepto/noqt.h>
   #include <lepto/string.h>
   #define QString CString

#else
   #include <QString>
   #include <QObject>
#endif


//---Declarations--------------------------------------------------------------


#ifdef TCB
typedef int (*ansiParserOtherCommandFunc_t)(char, QString &);
typedef void (*ansiParserlineEndReachedFunc_t)(void);
#endif


class CAnsiParser
      :public QObject
{
   Q_OBJECT

   private:
      enum EParserState{
         eParserStateNone,
         eParserStateEscaped,
         eParserStateCsi,
         eParserStateTelegram,
         eParserStateParam,
         eParserStateFinished,
      };
      const QString *input;
      bool error;
      QString output;
      bool spanPending;
      bool parPending;
      QString param;
      int pos;
      bool m_atEndOfLine;
      EParserState eParserState;
      bool m_addBreak;

   signals:
      void lineEndReached();
      int otherCommand(char command, QString &param);

   public:
      CAnsiParser();
      void clearOutput();
      bool atEndOfLine();

      void parse(const QString &_input);
      void closePending();
      bool isPending();
      void parseCsi();
      void parseTelegram();
      void parseBiwak();
      void parseColor();
      void resetParam();
      const QString &getOutput();
      void setAddBreak(bool addBreak)
      {
         m_addBreak=addBreak;
      }

      #ifdef TCB
      void setOtherCommandFunc(ansiParserOtherCommandFunc_t _ansiParserOtherCommandFunc);
      void setLineEndReachedFunc(ansiParserlineEndReachedFunc_t _ansiParserlineEndReachedFunc);
      #endif
};

QString ansi2html(const QString &line);


//---fin----------------------------------------------------------------------
#endif // ? ! __ANSIPARSER_H__
