char* XMLEntity::ToString(bool encoded, int level) { string text = ""; string indent = ""; string character_data = EscapeText(CharacterData()); for(int i=0; i<level; ++i) indent += "\t"; text = indent; text += "<"; text += Name(); for(int i=0; i < CountAttributes(); ++i) { text += " "; text += AttributeKey(i); text += "="; text += "\""; text += EscapeText(AttributeValue(i)); text += "\""; } if (character_data.size() == 0 && CountChildren() == 0) text += "/"; text += ">"; text += character_data; if (CountChildren() > 0) { text += "\n"; for (int i=0; i < CountChildren(); ++i) { char *str = Child(i)->ToString(encoded, level + 1); if (str) { text += str; free(str); } } text += indent; } if (CountChildren() > 0 || character_data.size() > 0) { text += "</"; text += Name(); text += ">"; } text += "\n"; return strdup(text.c_str()); }
void FDefaultRichTextMarkupWriter::Write(const TArray<FRichTextLine>& InLines, FString& Output) { for (int32 LineIndex = 0; LineIndex < InLines.Num(); ++LineIndex) { const FRichTextLine& Line = InLines[LineIndex]; // Append \n to the end of the previous line if(LineIndex > 0) { Output.AppendChar('\n'); } for (const FRichTextRun& Run : Line.Runs) { // Our rich-text format takes the form of <Name metakey1="metavalue1" metakey2="metavalue2">The Text</> const bool bHasTag = !Run.Info.Name.IsEmpty(); if (bHasTag) { Output.AppendChar('<'); Output.Append(Run.Info.Name); for(const TPair<FString, FString>& MetaDataEntry : Run.Info.MetaData) { Output.AppendChar(' '); Output.Append(MetaDataEntry.Key); Output.AppendChar('='); Output.AppendChar('"'); Output.Append(MetaDataEntry.Value); Output.AppendChar('"'); } Output.AppendChar('>'); } FString RunText = Run.Text; EscapeText(RunText); Output.Append(RunText); if (bHasTag) { Output.Append(TEXT("</>")); } } } }