@@ -87,29 +87,29 @@ bool ProjMgrYamlEmitter::WriteFile(YAML::Node& rootNode, const std::string& file
8787 return true ;
8888}
8989
90+ string ProjMgrYamlEmitter::EraseGeneratedByNode (const string& inStr) {
91+ size_t startIndex, endIndex;
92+ string outStr = inStr;
93+ startIndex = outStr.find (YAML_GENERATED_BY, 0 );
94+ endIndex = outStr.find (' \n ' , startIndex);
95+ if (startIndex != std::string::npos && endIndex != std::string::npos) {
96+ outStr = outStr.erase (startIndex, endIndex - startIndex);
97+ }
98+ return outStr;
99+ };
100+
90101bool ProjMgrYamlEmitter::CompareFile (const string& filename, const YAML::Node& rootNode) {
91- if (!RteFsUtils::Exists (filename)) {
102+ string inBuffer;
103+ if (!RteFsUtils::Exists (filename) || !RteFsUtils::ReadFile (filename, inBuffer)) {
92104 return false ;
93105 }
94- const YAML::Node& yamlRoot = YAML::LoadFile (filename);
95-
96- // emit and load rootNode to ensure both comparison sides have the same formatting
97106 YAML::Emitter emitter;
98- return CompareNodes (yamlRoot, YAML::Load ((emitter << rootNode).c_str ()));
107+ const auto & outBuffer = string ((emitter << rootNode).c_str ()) + ' \n ' ;
108+ return ProjMgrUtils::NormalizeLineEndings (EraseGeneratedByNode (inBuffer)) ==
109+ ProjMgrUtils::NormalizeLineEndings (EraseGeneratedByNode (outBuffer));
99110}
100111
101112bool ProjMgrYamlEmitter::CompareNodes (const YAML::Node& lhs, const YAML::Node& rhs) {
102- auto eraseGenNode = [](const string& inStr) {
103- size_t startIndex, endIndex;
104- string outStr = inStr;
105- startIndex = outStr.find (YAML_GENERATED_BY, 0 );
106- endIndex = outStr.find (' \n ' , startIndex);
107- if (startIndex != std::string::npos && endIndex != std::string::npos) {
108- outStr = outStr.erase (startIndex, endIndex - startIndex);
109- }
110- return outStr;
111- };
112-
113113 YAML::Emitter lhsEmitter, rhsEmitter;
114114 string lhsData, rhsData;
115115
@@ -118,8 +118,8 @@ bool ProjMgrYamlEmitter::CompareNodes(const YAML::Node& lhs, const YAML::Node& r
118118 rhsEmitter << rhs;
119119
120120 // remove generated-by node from the string
121- lhsData = eraseGenNode (lhsEmitter.c_str ());
122- rhsData = eraseGenNode (rhsEmitter.c_str ());
121+ lhsData = EraseGeneratedByNode (lhsEmitter.c_str ());
122+ rhsData = EraseGeneratedByNode (rhsEmitter.c_str ());
123123
124124 return (lhsData == rhsData) ? true : false ;
125125}
0 commit comments