Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML export: fix comment in comment #2098

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading