summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-05-31 14:37:54 +0200
committerLudovic Courtès <ludo@gnu.org>2016-05-31 18:22:14 +0200
commit75abbd0cbe2c42f07fa104f97bd206891eb576ef (patch)
tree00b142a62feffa35baca05fac896e14f10e7fc46
parent23aab4ab2cb8464b3c7907c8a164fd5710a24e0e (diff)
daemon: Remove unused XML output code.
* nix/local.mk (libutil_a_SOURCES): Remove libutil/xml-writer.cc. (libutil_headers): Remove libutil/xml-writer.hh. * nix/libutil/xml-writer.hh, nix/libutil/xml-writer.cc: Remove.
-rw-r--r--nix/libutil/xml-writer.cc94
-rw-r--r--nix/libutil/xml-writer.hh69
-rw-r--r--nix/local.mk2
3 files changed, 0 insertions, 165 deletions
diff --git a/nix/libutil/xml-writer.cc b/nix/libutil/xml-writer.cc
deleted file mode 100644
index 01794001b2c..00000000000
--- a/nix/libutil/xml-writer.cc
+++ /dev/null
@@ -1,94 +0,0 @@
1#include <assert.h>
2
3#include "xml-writer.hh"
4
5
6namespace nix {
7
8
9XMLWriter::XMLWriter(bool indent, std::ostream & output)
10 : output(output), indent(indent)
11{
12 output << "<?xml version='1.0' encoding='utf-8'?>" << std::endl;
13 closed = false;
14}
15
16
17XMLWriter::~XMLWriter()
18{
19 close();
20}
21
22
23void XMLWriter::close()
24{
25 if (closed) return;
26 while (!pendingElems.empty()) closeElement();
27 closed = true;
28}
29
30
31void XMLWriter::indent_(unsigned int depth)
32{
33 if (!indent) return;
34 output << string(depth * 2, ' ');
35}
36
37
38void XMLWriter::openElement(const string & name,
39 const XMLAttrs & attrs)
40{
41 assert(!closed);
42 indent_(pendingElems.size());
43 output << "<" << name;
44 writeAttrs(attrs);
45 output << ">";
46 if (indent) output << std::endl;
47 pendingElems.push_back(name);
48}
49
50
51void XMLWriter::closeElement()
52{
53 assert(!pendingElems.empty());
54 indent_(pendingElems.size() - 1);
55 output << "</" << pendingElems.back() << ">";
56 if (indent) output << std::endl;
57 pendingElems.pop_back();
58 if (pendingElems.empty()) closed = true;
59}
60
61
62void XMLWriter::writeEmptyElement(const string & name,
63 const XMLAttrs & attrs)
64{
65 assert(!closed);
66 indent_(pendingElems.size());
67 output << "<" << name;
68 writeAttrs(attrs);
69 output << " />";
70 if (indent) output << std::endl;
71}
72
73
74void XMLWriter::writeAttrs(const XMLAttrs & attrs)
75{
76 for (XMLAttrs::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
77 output << " " << i->first << "=\"";
78 for (unsigned int j = 0; j < i->second.size(); ++j) {
79 char c = i->second[j];
80 if (c == '"') output << "&quot;";
81 else if (c == '<') output << "&lt;";
82 else if (c == '>') output << "&gt;";
83 else if (c == '&') output << "&amp;";
84 /* Escape newlines to prevent attribute normalisation (see
85 XML spec, section 3.3.3. */
86 else if (c == '\n') output << "&#xA;";
87 else output << c;
88 }
89 output << "\"";
90 }
91}
92
93
94}
diff --git a/nix/libutil/xml-writer.hh b/nix/libutil/xml-writer.hh
deleted file mode 100644
index 3cefe3712c0..00000000000
--- a/nix/libutil/xml-writer.hh
+++ /dev/null
@@ -1,69 +0,0 @@
1#pragma once
2
3#include <iostream>
4#include <string>
5#include <list>
6#include <map>
7
8
9namespace nix {
10
11using std::string;
12using std::map;
13using std::list;
14
15
16typedef map<string, string> XMLAttrs;
17
18
19class XMLWriter
20{
21private:
22
23 std::ostream & output;
24
25 bool indent;
26 bool closed;
27
28 list<string> pendingElems;
29
30public:
31
32 XMLWriter(bool indent, std::ostream & output);
33 ~XMLWriter();
34
35 void close();
36
37 void openElement(const string & name,
38 const XMLAttrs & attrs = XMLAttrs());
39 void closeElement();
40
41 void writeEmptyElement(const string & name,
42 const XMLAttrs & attrs = XMLAttrs());
43
44private:
45 void writeAttrs(const XMLAttrs & attrs);
46
47 void indent_(unsigned int depth);
48};
49
50
51class XMLOpenElement
52{
53private:
54 XMLWriter & writer;
55public:
56 XMLOpenElement(XMLWriter & writer, const string & name,
57 const XMLAttrs & attrs = XMLAttrs())
58 : writer(writer)
59 {
60 writer.openElement(name, attrs);
61 }
62 ~XMLOpenElement()
63 {
64 writer.closeElement();
65 }
66};
67
68
69}
diff --git a/nix/local.mk b/nix/local.mk
index be57894eafc..07a92f74eac 100644
--- a/nix/local.mk
+++ b/nix/local.mk
@@ -55,7 +55,6 @@ libutil_a_SOURCES = \
55 %D%/libutil/affinity.cc \ 55 %D%/libutil/affinity.cc \
56 %D%/libutil/serialise.cc \ 56 %D%/libutil/serialise.cc \
57 %D%/libutil/util.cc \ 57 %D%/libutil/util.cc \
58 %D%/libutil/xml-writer.cc \
59 %D%/libutil/hash.cc \ 58 %D%/libutil/hash.cc \
60 %D%/libutil/gcrypt-hash.cc 59 %D%/libutil/gcrypt-hash.cc
61 60
@@ -63,7 +62,6 @@ libutil_headers = \
63 %D%/libutil/affinity.hh \ 62 %D%/libutil/affinity.hh \
64 %D%/libutil/hash.hh \ 63 %D%/libutil/hash.hh \
65 %D%/libutil/serialise.hh \ 64 %D%/libutil/serialise.hh \
66 %D%/libutil/xml-writer.hh \
67 %D%/libutil/util.hh \ 65 %D%/libutil/util.hh \
68 %D%/libutil/archive.hh \ 66 %D%/libutil/archive.hh \
69 %D%/libutil/types.hh \ 67 %D%/libutil/types.hh \