14 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)> filter,
17 DomKind k1 = i1.domKind();
18 DomKind k2 = i2.domKind();
20 if (!change(basePath, i1, i2))
26 case DomKind::Object: {
27 QStringList f1 = i1.fields();
28 QStringList f2 = i2.fields();
33 while (it1 != f1.size() || it2 != f2.size()) {
36 bool hasK1 = it1 != f1.size();
39 auto fieldOf = [](
const QString &name) {
40 auto fn = fieldNameFromString(name);
49 bool hasK2 = it2 != f2.size();
57 if (hasK1 && !filt1) {
62 }
else if (hasK2 && !filt2) {
66 if (filt1 && filt2 && k1 == k2) {
67 if (!domCompare(el1, el2, change, filter, basePath.withField(fieldOf(k1))))
71 }
else if (!hasK1 || (hasK2 && k1 > k2)) {
83 QStringList f1 = i1.sortedKeys();
84 QStringList f2 = i2.sortedKeys();
87 while (it1 != f1.size() || it2 != f2.size()) {
90 bool hasK1 = it1 != f1.size();
97 bool hasK2 = it2 != f2.size();
105 if (hasK1 && !filt1) {
110 }
else if (hasK2 && !filt2) {
114 if (filt1 && filt2 && k1 == k2) {
115 if (!domCompare(el1, el2, change, filter, basePath.withKey(k1)))
119 }
else if (!hasK1 || (hasK2 && k1 > k2)) {
130 case DomKind::List: {
133 index_type len1 = i1.indexes();
134 index_type len2 = i2.indexes();
136 return change(basePath, i1, i2);
137 for (index_type i = 0; i < len1; ++i) {
140 if (filter(i1,
PathEls::Index(i), v1) && filter(i2,
PathEls::Index(i), v2)) {
143 if (i1.isCanonicalChild(el1) && i2.isCanonicalChild(el2)
144 && !domCompare(el1, el2, change, filter, basePath.withIndex(i)))
149 case DomKind::Value: {
150 QCborValue v1 = i1.value();
151 QCborValue v2 = i2.value();
153 return change(basePath, i1, i2);
155 case DomKind::ScriptElement: {
167 function_ref<
bool(
const DomItem &,
const PathEls::PathComponent &,
const DomItem &)
const> filter,
171 bool hasDiff =
false;
174 [&res, &hasDiff, stopAtFirstDiff](
const Path &p,
const DomItem &j1,
const DomItem &j2) {
177 res.append(QStringLiteral(
"- %1\n").arg(p.toString()));
179 res.append(QStringLiteral(
"+ %1\n").arg(p.toString()));
181 DomKind k1 = j1.domKind();
182 DomKind k2 = j2.domKind();
185 QStringLiteral(
"- %1 %2\n").arg(p.toString(), domKindToString(k1)));
187 QStringLiteral(
"+ %1 %2\n").arg(p.toString(), domKindToString(k2)));
191 case DomKind::Object:
195 case DomKind::List: {
196 index_type len1 = j1.indexes();
197 index_type len2 = j2.indexes();
198 res.append(QStringLiteral(
"- %1 #%2\n").arg(p.toString()).arg(len1));
199 res.append(QStringLiteral(
"+ %1 #%2\n").arg(p.toString()).arg(len2));
201 case DomKind::Value: {
202 QCborValue v1 = j1.value();
203 QCborValue v2 = j2.value();
207 res.append(QStringLiteral(
"- %1 type(%2)\n")
210 res.append(QStringLiteral(
"+ %1 type(%2)\n")
214 res.append(QStringLiteral(
"- %1 value(%2)\n")
216 .arg(j1.toString()));
217 res.append(QStringLiteral(
"+ %1 value(%2)\n")
219 .arg(j2.toString()));
222 case DomKind::ScriptElement: {
232 if (hasDiff && res.isEmpty())
233 res.append(QStringLiteral(u"Had changes!"));
bool domCompare(const DomItem &i1, const DomItem &i2, function_ref< bool(Path, const DomItem &, const DomItem &)> change, function_ref< bool(const DomItem &, const PathEls::PathComponent &, const DomItem &)> filter, Path basePath)