Changeset View
Changeset View
Standalone View
Standalone View
source/ps/XML/XMLWriter.cpp
/* Copyright (C) 2013 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | ret.Replace("--", "\xE2\x80\x90\xE2\x80\x90"); | ||||
// any alternative | // any alternative | ||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
enum { EL_ATTR, EL_TEXT, EL_SUBEL }; | enum { EL_ATTR, EL_TEXT, EL_SUBEL }; | ||||
XMLWriter_File::XMLWriter_File() | XMLWriter_File::XMLWriter_File() | ||||
: m_Indent(0), m_LastElement(NULL), | : m_Indent(0), m_LastElement(nullptr), | ||||
m_PrettyPrint(true) | m_PrettyPrint(true) | ||||
{ | { | ||||
// Encoding is always UTF-8 - that's one of the only two guaranteed to be | // Encoding is always UTF-8 - that's one of the only two guaranteed to be | ||||
// supported by XML parsers (along with UTF-16), and there's not much need | // supported by XML parsers (along with UTF-16), and there's not much need | ||||
// to let people choose another. | // to let people choose another. | ||||
m_Data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | m_Data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | ||||
} | } | ||||
Show All 33 Lines | XERO_ITER_ATTR(el, attr) | ||||
writer.Attribute(file.GetAttributeString(attr.Name).c_str(), attr.Value); | writer.Attribute(file.GetAttributeString(attr.Name).c_str(), attr.Value); | ||||
XERO_ITER_EL(el, child) | XERO_ITER_EL(el, child) | ||||
ElementXMB(file, child); | ElementXMB(file, child); | ||||
} | } | ||||
void XMLWriter_File::Comment(const char* text) | void XMLWriter_File::Comment(const char* text) | ||||
{ | { | ||||
ElementStart(NULL, "!-- "); | ElementStart(nullptr, "!-- "); | ||||
m_Data += escapeComment(text); | m_Data += escapeComment(text); | ||||
m_Data += " -->"; | m_Data += " -->"; | ||||
--m_Indent; | --m_Indent; | ||||
} | } | ||||
CStr XMLWriter_File::Indent() | CStr XMLWriter_File::Indent() | ||||
{ | { | ||||
return std::string(m_Indent, '\t'); | return std::string(m_Indent, '\t'); | ||||
Show All 18 Lines | |||||
void XMLWriter_File::ElementClose() | void XMLWriter_File::ElementClose() | ||||
{ | { | ||||
m_Data += ">"; | m_Data += ">"; | ||||
} | } | ||||
void XMLWriter_File::ElementEnd(const char* name, int type) | void XMLWriter_File::ElementEnd(const char* name, int type) | ||||
{ | { | ||||
--m_Indent; | --m_Indent; | ||||
m_LastElement = NULL; | m_LastElement = nullptr; | ||||
switch (type) | switch (type) | ||||
{ | { | ||||
case EL_ATTR: | case EL_ATTR: | ||||
m_Data += "/>"; | m_Data += "/>"; | ||||
break; | break; | ||||
case EL_TEXT: | case EL_TEXT: | ||||
m_Data += "</"; | m_Data += "</"; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// | // | ||||
template <> void XMLWriter_File::ElementAttribute<const char*>(const char* name, const char* const& value, bool newelement) | template <> void XMLWriter_File::ElementAttribute<const char*>(const char* name, const char* const& value, bool newelement) | ||||
{ | { | ||||
if (newelement) | if (newelement) | ||||
{ | { | ||||
ElementStart(NULL, name); | ElementStart(nullptr, name); | ||||
m_Data += ">"; | m_Data += ">"; | ||||
ElementText(value, false); | ElementText(value, false); | ||||
ElementEnd(name, EL_TEXT); | ElementEnd(name, EL_TEXT); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
ENSURE(m_LastElement && m_LastElement->m_Type == EL_ATTR); | ENSURE(m_LastElement && m_LastElement->m_Type == EL_ATTR); | ||||
m_Data += " "; | m_Data += " "; | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator