Skip to content

Commit

Permalink
XML export: fix comment in comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeMartinez committed Jul 25, 2024
1 parent 88f3ea4 commit c23365e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Source/MediaInfo/OutputHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,23 @@ string To_XML (Node& Cur_Node, const int& Level, bool Print_Header, bool Indent)
if (Level)
Result+="\n";

bool CommentedNow;
if (!Cur_Node.XmlCommentOut.empty())
{
Result+=(Indent?string(Level, '\t'):string())+"<!-- "+Cur_Node.XmlCommentOut;
Result+=(Indent?string(Level, '\t'):string())+(Cur_Node.AlreadyCommented?"<!- ":"<!-- ")+Cur_Node.XmlCommentOut;

// If the node name is empty, just print the comment
if (Cur_Node.Name.empty())
{
Result += " -->";
Result += Cur_Node.AlreadyCommented?" ->":" -->";
return Result;
}
Result+="\n";
CommentedNow=!Cur_Node.AlreadyCommented;
Cur_Node.AlreadyCommented=true;
}
else
CommentedNow=false;

Result+=(Indent?string(Level, '\t'):string())+"<"+Cur_Node.Name;

Expand All @@ -142,9 +147,9 @@ string To_XML (Node& Cur_Node, const int& Level, bool Print_Header, bool Indent)
{
Result+=" />";
if (!Cur_Node.XmlComment.empty() && Cur_Node.XmlCommentOut.empty())
Result+=" <!-- "+Cur_Node.XmlComment+" -->";
Result+=(Cur_Node.AlreadyCommented?" <!- ":" <!-- ")+Cur_Node.XmlComment+(Cur_Node.AlreadyCommented?" ->":" -->");
if (Cur_Node.XmlCommentOut.size())
Result+="\n"+(Indent?string(Level, '\t'):string())+"-->";
Result+="\n"+(Indent?string(Level, '\t'):string())+((Cur_Node.AlreadyCommented && !CommentedNow)?"->":"-->");
return Result;
}

Expand All @@ -162,13 +167,14 @@ string To_XML (Node& Cur_Node, const int& Level, bool Print_Header, bool Indent)
{
CanDisplayXmlComment=false;
if (!Cur_Node.XmlComment.empty() && Cur_Node.XmlCommentOut.empty())
Result+=" <!-- "+Cur_Node.XmlComment+" -->";
Result+=(Cur_Node.AlreadyCommented?" <!- ":" <!-- ")+Cur_Node.XmlComment+(Cur_Node.AlreadyCommented?" ->":" -->");

for (size_t Pos=0; Pos<Cur_Node.Childs.size(); Pos++)
{
if (!Cur_Node.Childs[Pos])
continue;

Cur_Node.Childs[Pos]->AlreadyCommented=Cur_Node.AlreadyCommented;
Result+=To_XML(*Cur_Node.Childs[Pos], Level+1, false, Indent);
delete Cur_Node.Childs[Pos];
Cur_Node.Childs[Pos]=NULL;
Expand All @@ -181,9 +187,9 @@ string To_XML (Node& Cur_Node, const int& Level, bool Print_Header, bool Indent)

Result+="</"+Cur_Node.Name+">";
if (Cur_Node.XmlCommentOut.size())
Result+="\n"+(Indent?string(Level, '\t'):string())+"-->";
Result+="\n"+(Indent?string(Level, '\t'):string())+((Cur_Node.AlreadyCommented && !CommentedNow)?"->":"-->");
else if (!Cur_Node.XmlComment.empty() && CanDisplayXmlComment)
Result+=" <!-- "+Cur_Node.XmlComment+" -->";
Result+=(Cur_Node.AlreadyCommented?" <!- ":" <!-- ")+Cur_Node.XmlComment+(Cur_Node.AlreadyCommented?" ->":" -->");
if (!Level)
Result+="\n";

Expand Down
1 change: 1 addition & 0 deletions Source/MediaInfo/OutputHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Node
std::string XmlCommentOut; //If set, comment out the whole node in the xml output with the string as comment
std::string RawContent; //If set, replace the whole node by the string
bool Multiple;
bool AlreadyCommented=false;

//Constructors
Node()
Expand Down

0 comments on commit c23365e

Please sign in to comment.