| 50 | |
| 51 | |
| 52 | static bool CompareAttributes( |
| 53 | const pugi::xml_node& node1, |
| 54 | const pugi::xml_node& node2, |
| 55 | const TXmlComparisonContext& comparisonContext, |
| 56 | TString* diffString) { |
| 57 | |
| 58 | const auto* ignoredAttributesMap = comparisonContext.IgnoredAttributes.FindPtr(node1.path()); |
| 59 | |
| 60 | size_t attrIdx = 0; // for output |
| 61 | auto attrIter1 = node1.attributes_begin(); |
| 62 | auto attrIter2 = node2.attributes_begin(); |
| 63 | |
| 64 | while (true) { |
| 65 | if (attrIter1 == node1.attributes_end()) { |
| 66 | if (attrIter2 == node2.attributes_end()) { |
| 67 | return true; |
| 68 | } else { |
| 69 | TStringOutput out(*diffString); |
| 70 | out << "node " << node1.path() << " has attribute \"" << attrIter2->name() |
| 71 | << "\" in model2 but not in model1"; |
| 72 | return false; |
| 73 | } |
| 74 | } else { |
| 75 | if (attrIter2 == node2.attributes_end()) { |
| 76 | TStringOutput out(*diffString); |
| 77 | out << "node " << node1.path() << " has attribute \"" << attrIter1->name() |
| 78 | << "\" in model1 but not in model2"; |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | if (std::strcmp(attrIter1->name(), attrIter2->name())) { |
| 83 | TStringOutput out(*diffString); |
| 84 | out << "node " << node1.path() << " has different attributes at index " << attrIdx |
| 85 | << ": model1 has \"" << attrIter1->name() << "\", model2 has \"" << attrIter2->name() |
| 86 | << "\""; |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | if (!ignoredAttributesMap || !ignoredAttributesMap->contains(attrIter1->name())) { |
| 91 | if (std::strcmp(attrIter1->value(), attrIter2->value())) { |
| 92 | TStringOutput out(*diffString); |
| 93 | out << "node " << node1.path() << ": attribute \"" << attrIter1->name() |
| 94 | << "\" has different values: model1 has \"" << attrIter1->value() |
| 95 | << "\", model2 has \"" << attrIter2->value() << "\""; |
| 96 | return false; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | ++attrIdx; |
| 101 | ++attrIter1; |
| 102 | ++attrIter2; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | Y_UNREACHABLE(); |
| 107 | return true; // make compiler happy |
| 108 | } |
| 109 |
no test coverage detected