File indexing completed on 2024-04-21 05:44:08
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 // lib 0011 #include "differencestring.h" 0012 // Qt 0013 #include <QString> 0014 0015 namespace KompareDiff2 0016 { 0017 0018 class Marker; 0019 class DifferenceString; 0020 0021 class DifferenceStringPair 0022 { 0023 public: 0024 DifferenceStringPair(DifferenceString *first, DifferenceString *second) 0025 : m_first(first) 0026 , m_second(second) 0027 , m_strFirst(QLatin1Char(' ') + first->string()) 0028 , m_strSecond(QLatin1Char(' ') + second->string()) 0029 , m_lengthFirst(m_strFirst.length()) 0030 , m_lengthSecond(m_strSecond.length()) 0031 , m_arrayFirst(m_strFirst.unicode()) 0032 , m_arraySecond(m_strSecond.unicode()) 0033 { 0034 // Actual contents must be indented by 1 0035 } 0036 bool equal(unsigned int firstIndex, unsigned int secondIndex) const 0037 { 0038 return m_arrayFirst[firstIndex] == m_arraySecond[secondIndex]; 0039 } 0040 unsigned int lengthFirst() const 0041 { 0042 return m_lengthFirst; 0043 } 0044 unsigned int lengthSecond() const 0045 { 0046 return m_lengthSecond; 0047 } 0048 MarkerList markerListFirst() const 0049 { 0050 return m_first->markerList(); 0051 } 0052 MarkerList markerListSecond() const 0053 { 0054 return m_second->markerList(); 0055 } 0056 void prependFirst(Marker *marker) 0057 { 0058 m_first->prepend(marker); 0059 } 0060 void prependSecond(Marker *marker) 0061 { 0062 m_second->prepend(marker); 0063 } 0064 bool needFineGrainedOutput(unsigned int difference) const 0065 { 0066 return difference <= qMax(m_lengthFirst, m_lengthSecond) / 2; 0067 } 0068 const static bool allowReplace = true; 0069 0070 private: 0071 DifferenceString *m_first; 0072 DifferenceString *m_second; 0073 QString m_strFirst; 0074 QString m_strSecond; 0075 unsigned int m_lengthFirst; 0076 unsigned int m_lengthSecond; 0077 const QChar *m_arrayFirst; 0078 const QChar *m_arraySecond; 0079 }; 0080 0081 } 0082 0083 #endif // KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H