KompareDiff2

differencestringpair.h
1/*
2 SPDX-FileCopyrightText: 2011 Dmitry Risenberg <dmitry.risenberg@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H
8#define KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H
9
10// lib
11#include "differencestring.h"
12// Qt
13#include <QString>
14
15namespace KompareDiff2
16{
17
18class Marker;
19class DifferenceString;
20
21class DifferenceStringPair
22{
23public:
24 DifferenceStringPair(DifferenceString *first, DifferenceString *second)
25 : m_first(first)
26 , m_second(second)
27 , m_strFirst(QLatin1Char(' ') + first->string())
28 , m_strSecond(QLatin1Char(' ') + second->string())
29 , m_lengthFirst(m_strFirst.length())
30 , m_lengthSecond(m_strSecond.length())
31 , m_arrayFirst(m_strFirst.unicode())
32 , m_arraySecond(m_strSecond.unicode())
33 {
34 // Actual contents must be indented by 1
35 }
36 bool equal(unsigned int firstIndex, unsigned int secondIndex) const
37 {
38 return m_arrayFirst[firstIndex] == m_arraySecond[secondIndex];
39 }
40 unsigned int lengthFirst() const
41 {
42 return m_lengthFirst;
43 }
44 unsigned int lengthSecond() const
45 {
46 return m_lengthSecond;
47 }
48 MarkerList markerListFirst() const
49 {
50 return m_first->markerList();
51 }
52 MarkerList markerListSecond() const
53 {
54 return m_second->markerList();
55 }
56 void prependFirst(Marker *marker)
57 {
58 m_first->prepend(marker);
59 }
60 void prependSecond(Marker *marker)
61 {
62 m_second->prepend(marker);
63 }
64 bool needFineGrainedOutput(unsigned int difference) const
65 {
66 return difference <= qMax(m_lengthFirst, m_lengthSecond) / 2;
67 }
68 const static bool allowReplace = true;
69
70private:
71 DifferenceString *m_first;
72 DifferenceString *m_second;
73 QString m_strFirst;
74 QString m_strSecond;
75 unsigned int m_lengthFirst;
76 unsigned int m_lengthSecond;
77 const QChar *m_arrayFirst;
78 const QChar *m_arraySecond;
79};
80
81}
82
83#endif // KOMPAREDIFF2_DIFFERENCESTRINGPAIR_H
KompareDiff2 namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.