File indexing completed on 2024-04-28 17:01:39

0001 /*
0002 SPDX-FileCopyrightText: 2011 Dmitry Risenberg <dmitry.risenberg@gmail.com>
0003 
0004 SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H
0008 #define KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H
0009 
0010 #include <QString>
0011 
0012 #include "difference.h"
0013 
0014 namespace Diff2 {
0015 
0016 class Marker;
0017 class DifferenceString;
0018 
0019 class DifferenceStringPair {
0020 public:
0021     DifferenceStringPair(DifferenceString* first, DifferenceString* second)
0022         : m_first(first), m_second(second),
0023           m_strFirst(QLatin1Char(' ') + first->string()), m_strSecond(QLatin1Char(' ') + second->string()),
0024           m_lengthFirst(m_strFirst.length()), m_lengthSecond(m_strSecond.length()),
0025           m_arrayFirst(m_strFirst.unicode()), m_arraySecond(m_strSecond.unicode())
0026     {
0027         // Actual contents must be indented by 1
0028     }
0029     bool equal(unsigned int firstIndex, unsigned int secondIndex) const
0030     {
0031         return m_arrayFirst[firstIndex] == m_arraySecond[secondIndex];
0032     }
0033     unsigned int lengthFirst() const
0034     {
0035         return m_lengthFirst;
0036     }
0037     unsigned int lengthSecond() const
0038     {
0039         return m_lengthSecond;
0040     }
0041     MarkerList markerListFirst() const
0042     {
0043         return m_first->markerList();
0044     }
0045     MarkerList markerListSecond() const
0046     {
0047         return m_second->markerList();
0048     }
0049     void prependFirst(Marker* marker)
0050     {
0051         m_first->prepend(marker);
0052     }
0053     void prependSecond(Marker* marker)
0054     {
0055         m_second->prepend(marker);
0056     }
0057     bool needFineGrainedOutput(unsigned int difference) const
0058     {
0059         return difference <= qMax(m_lengthFirst, m_lengthSecond) / 2;
0060     }
0061     const static bool allowReplace = true;
0062 private:
0063     DifferenceString* m_first;
0064     DifferenceString* m_second;
0065     QString m_strFirst;
0066     QString m_strSecond;
0067     unsigned int m_lengthFirst;
0068     unsigned int m_lengthSecond;
0069     const QChar* m_arrayFirst;
0070     const QChar* m_arraySecond;
0071 };
0072 
0073 }
0074 
0075 #endif // KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H