Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmldiffer_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQMLDIFFER_P_H
6#define QQMLDIFFER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19// This code is adapted from QtCreator/src/libs/utils/differ.
20
21#include <QHash>
22#include <QString>
23
24QT_BEGIN_NAMESPACE
25
26namespace QQmlLSUtils {
27
28class Diff
29{
30public:
38 Diff() = default;
39 Diff(Command com, const QString &txt = {});
40 bool operator==(const Diff &other) const;
41 bool operator!=(const Diff &other) const;
42};
43
44class Differ
45{
46public:
53 Differ();
54 QList<Diff> diff(const QString &text1, const QString &text2);
55 QList<Diff> unifiedDiff(const QString &text1, const QString &text2);
56 void setDiffMode(DiffMode mode);
57 DiffMode diffMode() const;
58 static QList<Diff> merge(const QList<Diff> &diffList);
59
60private:
61 QList<Diff> preprocess1AndDiff(const QString &text1, const QString &text2);
62 QList<Diff> preprocess2AndDiff(const QString &text1, const QString &text2);
63 QList<Diff> diffMyers(const QString &text1, const QString &text2);
64 QList<Diff> diffMyersSplit(const QString &text1, qsizetype x,
65 const QString &text2, qsizetype y);
66 QList<Diff> diffNonCharMode(const QString &text1, const QString &text2);
67 QStringList encode(const QString &text1,
68 const QString &text2,
69 QString *encodedText1,
70 QString *encodedText2);
71 QString encode(const QString &text,
72 QStringList *lines,
73 QHash<QString, qsizetype> *lineToCode);
74 qsizetype findSubtextEnd(const QString &text,
75 qsizetype subTextStart);
76
77 DiffMode m_diffMode = Differ::LineMode;
78 DiffMode m_currentDiffMode = Differ::LineMode;
79};
80
81} // namespace QQmlLSUtils
82
83QT_END_NAMESPACE
84
85#endif // QQMLDIFFER_P_H
bool operator==(const Diff &other) const
bool operator!=(const Diff &other) const
Diff(Command com, const QString &txt={})
QList< Diff > diff(const QString &text1, const QString &text2)
DiffMode diffMode() const
QList< Diff > unifiedDiff(const QString &text1, const QString &text2)
void setDiffMode(DiffMode mode)
static QList< Diff > merge(const QList< Diff > &diffList)
static QList< Diff > decode(const QList< Diff > &diffList, const QStringList &lines)
static qsizetype commonSuffix(const QString &text1, const QString &text2)
static qsizetype commonPrefix(const QString &text1, const QString &text2)
static QList< Diff > squashEqualities(const QList< Diff > &diffList)
Combined button and popup list for selecting options.