Open main menu

User:PerfektesChaos/WikidiffLX/coding/WikidiffLX.h

Declarations for WikidiffLX.cpp based on wikidiff2/wikidiff2.h (rev 67994 Jun 2010).

Cutting off WDLX_config.h configuration with definition of WDLX_ALLOCATOR.

Major changes:

  • some unused typedef discarded
  • change from StringVector and StringDiff to LineVector and LineDiff
  • new members scratch256 and numberContextL
  • various new methods
  • some inline methods replaced by single direct use


#ifndef WIKIDIFFLX_H
#define WIKIDIFFLX_H

#include "WDLX_config.h"
#include "DiffEngine.h"
#include "Line.h"
#include "Word.h"
#include <vector>

class WikidiffLX {
   public:
      typedef std::basic_string<char, std::char_traits<char>, WDLX_ALLOCATOR<char> > String;

      const String & execute(const String & text1,
                             const String & text2,
                             int numContextLines);
      inline const String & getResult() const;

   protected:
      typedef String::const_iterator Iterator;
      typedef std::vector<int, WDLX_ALLOCATOR<int> > IntVector;
      typedef Diff<Line> LineDiff;
      typedef Diff<Word> WordDiff;
      typedef std::vector<Line, WDLX_ALLOCATOR<Line> > LineVector;
      typedef std::vector<Word, WDLX_ALLOCATOR<Word> > WordVector;
      typedef std::vector<const Line *, WDLX_ALLOCATOR<const Line *> > LinePVector;
      typedef std::vector<WordVector, WDLX_ALLOCATOR<WordVector> > WordsVector;
      typedef std::vector<WordDiff, WDLX_ALLOCATOR<WordDiff> > WordDiffVector;

      String result;

   private:
#ifndef NO_LINE_NUMBERS
      char scratch256[256];
#endif
      unsigned int numberContextL;

      void diffAdjustSingle(LineVector vector,
                            const int opMerge);
      bool diffIncompleteChanges(LineVector vector);
      void diffResult(const LineDiff linediff);
      void diffWhitespace(LineVector from);
      void explodeLines(const String & text,
                        LineVector & lines);
      void explodeWords(const Line::Iterator pB,
                        const Line::Iterator pE,
                        WordVector & words);
      void explodeWordSuffix(bool & livingWord,
                             const Iterator wordStart,
                             bool & livingSuffix,
                             const Iterator suffixStart,
                             const Iterator wordNext,
                             WordVector & words);
      void explodeWordsThai(unsigned int ch,
                            Iterator & p,
                            const Iterator pE,
                            WordVector & words,
                            Iterator & wordStart);
      void findPunctSpace(const Iterator pB,
                          const Iterator pE,
                          const unsigned char punct,
                          Iterator * p);
      void findVirtualBreak(const Iterator pB,
                            const Iterator pE,
                            Iterator * p);
      unsigned int nextUtf8Char(Iterator & p,
                                unsigned char b,
                                const Iterator pE);
      int printLineChange(const LineVector change,
                          const size_t n,
                          const bool left,
                          size_t * i,
                          WordsVector * wordsTo,
                          WordDiffVector * worddiffs);
      void printLineChangeRow(const LineVector from,
                              const LineVector to,
                              const size_t nFrom,
                              const size_t nTo,
                              size_t * iFrom,
                              size_t * iTo);
      void printLineNumber(const Line f,
                           const Line t);
      int printLineSingleCell(const LineVector context,
                              const size_t n,
                              size_t * i);
      void printLines(const LineVector from,
                      const LineVector to);
      int printLinesAdd(const LineVector to,
                        const size_t nTo,
                        size_t * iTo);
      void printLinesChange(const LineVector from,
                            const LineVector to,
                            const size_t nFrom,
                            const size_t nTo,
                            size_t * iFrom,
                            size_t * iTo);
      void printLinesContext(const LineVector from,
                             const LineVector to,
                             const size_t nFrom,
                             const size_t nTo,
                             size_t * iFrom,
                             size_t * iTo);
      void printLinesContextRow(const LineVector context,
                                const size_t iBeg,
                                const size_t iEnd);
      void printLinesContextRows(const LineVector context,
                                 const size_t iBeg,
                                 const size_t iEnd);
      int printLinesDelete(const LineVector from,
                           const size_t nFrom,
                           size_t * iFrom);
      void printLinesDiff(const LineVector from,
                          const LineVector to,
                          const size_t nFrom,
                          const size_t nTo,
                          size_t * iFrom,
                          size_t * iTo);
      void printSpacediff(const size_t n);
      void printText(const String & input);
      void printTextRed(const String & text);
      void printWordDiff(WordDiff worddiff,
                         const bool added);
      void debugPrintWordDiff(WordDiff & worddiff);
      void printWordDiffBlack(const DiffOp<Word>::PointerVector current,
                              const DiffOp<Word>::PointerVector others,
                              const bool lastBlack,
                              String & word);
      void recoverParagraphs(LineVector from,
                             LineVector to);
      WordDiff wordDiff(const String & text1,
                        const String & text2);
};
const WikidiffLX::String & WikidiffLX::getResult() const
{
   return result;
}


#endif