diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2016-05-31 14:37:54 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2016-05-31 18:22:14 +0200 |
| commit | 75abbd0cbe2c42f07fa104f97bd206891eb576ef (patch) | |
| tree | 00b142a62feffa35baca05fac896e14f10e7fc46 | |
| parent | 23aab4ab2cb8464b3c7907c8a164fd5710a24e0e (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.cc | 94 | ||||
| -rw-r--r-- | nix/libutil/xml-writer.hh | 69 | ||||
| -rw-r--r-- | nix/local.mk | 2 |
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 | |||
| 6 | namespace nix { | ||
| 7 | |||
| 8 | |||
| 9 | XMLWriter::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 | |||
| 17 | XMLWriter::~XMLWriter() | ||
| 18 | { | ||
| 19 | close(); | ||
| 20 | } | ||
| 21 | |||
| 22 | |||
| 23 | void XMLWriter::close() | ||
| 24 | { | ||
| 25 | if (closed) return; | ||
| 26 | while (!pendingElems.empty()) closeElement(); | ||
| 27 | closed = true; | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | void XMLWriter::indent_(unsigned int depth) | ||
| 32 | { | ||
| 33 | if (!indent) return; | ||
| 34 | output << string(depth * 2, ' '); | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | void 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 | |||
| 51 | void 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 | |||
| 62 | void 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 | |||
| 74 | void 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 << """; | ||
| 81 | else if (c == '<') output << "<"; | ||
| 82 | else if (c == '>') output << ">"; | ||
| 83 | else if (c == '&') output << "&"; | ||
| 84 | /* Escape newlines to prevent attribute normalisation (see | ||
| 85 | XML spec, section 3.3.3. */ | ||
| 86 | else if (c == '\n') output << "
"; | ||
| 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 | |||
| 9 | namespace nix { | ||
| 10 | |||
| 11 | using std::string; | ||
| 12 | using std::map; | ||
| 13 | using std::list; | ||
| 14 | |||
| 15 | |||
| 16 | typedef map<string, string> XMLAttrs; | ||
| 17 | |||
| 18 | |||
| 19 | class XMLWriter | ||
| 20 | { | ||
| 21 | private: | ||
| 22 | |||
| 23 | std::ostream & output; | ||
| 24 | |||
| 25 | bool indent; | ||
| 26 | bool closed; | ||
| 27 | |||
| 28 | list<string> pendingElems; | ||
| 29 | |||
| 30 | public: | ||
| 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 | |||
| 44 | private: | ||
| 45 | void writeAttrs(const XMLAttrs & attrs); | ||
| 46 | |||
| 47 | void indent_(unsigned int depth); | ||
| 48 | }; | ||
| 49 | |||
| 50 | |||
| 51 | class XMLOpenElement | ||
| 52 | { | ||
| 53 | private: | ||
| 54 | XMLWriter & writer; | ||
| 55 | public: | ||
| 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 \ |
