26 " <!ENTITY nbsp \" \">\n"
27 " <!ENTITY acute \"´\">\n"
28 " <!ENTITY eacute \"é\">\n"
29 " <!ENTITY apostr \"'\">\n"
30 " <!ENTITY semi \";\">\n"
38 neu.reserve(str.length()*4);
41 for (string::const_iterator
s = str.begin();
s != str.end(); ++
s) {
43 const char *entity =
NULp;
46 case '<': { entity =
"lt";
break; }
47 case '>': { entity =
"gt";
break; }
48 case '&': { entity =
"amp";
break; }
49 case '\'': { entity =
"apostr";
break; }
50 case char(0xb4): { entity =
"acute";
break; }
51 case 'é': { entity =
"eacute";
break; }
52 default: { replace = *
s; }
56 neu.append(1, replace);
72 XML_Attribute::XML_Attribute(
const string& name_,
const string& content_) :
78 XML_Attribute::~XML_Attribute() {
81 XML_Attribute *XML_Attribute::append_to(XML_Attribute *queue) {
82 if (!queue)
return this;
83 queue->next = append_to(queue->next);
87 fprintf(out,
" %s=\"%s\"", name.c_str(),
encodeEntities(content,
true).c_str());
88 if (next) next->print(out);
118 XML_Tag::XML_Tag(
const string &name_) :
127 XML_Tag::~XML_Tag() {
135 void XML_Tag::add_attribute(
const string& name_,
const string& content_) {
136 XML_Attribute *newAttr =
new XML_Attribute(name_, content_);
137 attribute = newAttr->append_to(attribute);
140 void XML_Tag::add_attribute(
const string& name_,
int value) {
142 sprintf(buf,
"%i", value);
143 add_attribute(name_, buf);
146 void XML_Tag::add_son(
XML_Node *son_,
bool son_is_tag) {
147 if (son)
throw string(
"Tried to add a second son! Destroy previous son first.");
149 int wanted_state = son_is_tag ? 2 : 1;
150 if (state<wanted_state) state = wanted_state;
153 void XML_Tag::remove_son(
XML_Node *son_) {
154 if (son != son_)
throw string(
"Tried to remove wrong son!");
160 void XML_Tag::open(FILE *out) {
167 if (attribute) attribute->print(out);
172 void XML_Tag::close(FILE *out) {
181 if (attribute) attribute->print(out);
186 if (state >= 2 && onExtraLine) {
fputc(
'\n', out);
to_indent(out, Indent()); }
187 fprintf(out,
"</%s>", name.c_str());
200 throw string(
"Can't add son to XML_Text-Node");
204 throw string(
"Can't remove son from XML_Text-Node");
223 throw string(
"Can't add son to XML_Comment-Node");
227 throw string(
"Can't remove son from XML_Comment-Node");
242 XML_Document::XML_Document(
const string& name_,
const string& dtd_, FILE *out_)
246 skip_empty_tags(
false),
247 indentation_per_level(1)
253 root =
new XML_Tag(name_);
256 fputs(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", out);
257 fprintf(out,
"<!DOCTYPE %s SYSTEM '%s' [\n%s]>\n", name_.c_str(), dtd.c_str(),
entities);
260 XML_Document::~XML_Document() {
void remove_son(XML_Node *son_) OVERRIDE __ATTR__NORETURN
return string(buffer, length)
static string encodeEntities(const string &str, bool)
void add_son(XML_Node *son_, bool son_is_tag) OVERRIDE __ATTR__NORETURN
virtual void add_son(XML_Node *son_, bool son_is_tag)=0
void GBK_terminate(const char *error) __ATTR__NORETURN
XML_Document * the_XML_Document
fputs(TRACE_PREFIX, stderr)
static const char * entities
void open(FILE *) OVERRIDE
void to_indent(FILE *out, int indent)
virtual void remove_son(XML_Node *son_)=0
void close(FILE *out) OVERRIDE
virtual void open(FILE *out)=0
GB_write_int const char s