From ec5f59dac8d5eca3504ec5fe205dcb7d8fd382a6 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Nov 2009 06:00:12 +0000 Subject: Fixed support for nested elements and lists. Improved failure/error reporting monad. Minor code cleanup. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880598 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/sca/kernel/xml.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'cpp/sca/kernel/xml.hpp') diff --git a/cpp/sca/kernel/xml.hpp b/cpp/sca/kernel/xml.hpp index b7611b8477..8d561557ca 100644 --- a/cpp/sca/kernel/xml.hpp +++ b/cpp/sca/kernel/xml.hpp @@ -144,7 +144,7 @@ const value readAttribute(XMLReader& reader) { */ const value readToken(XMLReader& reader) { const int tokenType = reader.read(); - if (tokenType == XMLReader::End) + if (tokenType == XMLReader::None || tokenType == XMLReader::End) return value(); if (tokenType == XMLReader::Element) return startElement; @@ -228,7 +228,7 @@ const char* encoding = "UTF-8"; */ const list expandElementValues(const value& n, const list& l) { if (isNil(l)) - return list(); + return l; return cons(value(cons(element, cons(n, (list)car(l)))), expandElementValues(n, cdr(l))); } @@ -240,7 +240,7 @@ const failable writeList(const list& l, const xmlTextW const value token(car(l)); if (isTaggedList(token, attribute)) { if (xmlTextWriterWriteAttribute(xml, (const xmlChar*)std::string(attributeName(token)).c_str(), (const xmlChar*)std::string(attributeValue(token)).c_str()) < 0) - return std::string("xmlTextWriterWriteAttribute failed"); + return mkfailure("xmlTextWriterWriteAttribute failed"); } else if (isTaggedList(token, element)) { @@ -257,7 +257,7 @@ const failable writeList(const list& l, const xmlTextW // Write an element with a single value if (xmlTextWriterStartElement(xml, (const xmlChar*)std::string(elementName(token)).c_str()) < 0) - return std::string("xmlTextWriterStartElement failed"); + return mkfailure("xmlTextWriterStartElement failed"); // Write its children const failable w = writeList(elementChildren(token), xml); @@ -265,14 +265,14 @@ const failable writeList(const list& l, const xmlTextW return w; if (xmlTextWriterEndElement(xml) < 0) - return std::string("xmlTextWriterEndElement failed"); + return mkfailure("xmlTextWriterEndElement failed"); } } else { // Write an element if (xmlTextWriterStartElement(xml, (const xmlChar*)std::string(elementName(token)).c_str()) < 0) - return std::string("xmlTextWriterStartElement failed"); + return mkfailure("xmlTextWriterStartElement failed"); // Write its children const failable w = writeList(elementChildren(token), xml); @@ -280,13 +280,13 @@ const failable writeList(const list& l, const xmlTextW return w; if (xmlTextWriterEndElement(xml) < 0) - return std::string("xmlTextWriterEndElement failed"); + return mkfailure("xmlTextWriterEndElement failed"); } } else { // Write XML text if (xmlTextWriterWriteString(xml, (const xmlChar*)std::string(token).c_str()) < 0) - return std::string("xmlTextWriterWriteString failed"); + return mkfailure("xmlTextWriterWriteString failed"); } @@ -299,14 +299,14 @@ const failable writeList(const list& l, const xmlTextW */ const failable write(const list& l, const xmlTextWriterPtr xml) { if (xmlTextWriterStartDocument(xml, NULL, encoding, NULL) < 0) - return std::string("xmlTextWriterStartDocument failed"); + return mkfailure("xmlTextWriterStartDocument failed"); const failable w = writeList(l, xml); if (!hasValue(w)) return w; if (xmlTextWriterEndDocument(xml) < 0) - return std::string("xmlTextWriterEndDocument failed"); + return mkfailure("xmlTextWriterEndDocument failed"); return true; } @@ -337,15 +337,15 @@ template const failable writeXML(const lambda cx(reduce, initial); xmlOutputBufferPtr out = xmlOutputBufferCreateIO(writeCallback, NULL, &cx, NULL); if (out == NULL) - return std::string("xmlOutputBufferCreateIO failed"); + return mkfailure("xmlOutputBufferCreateIO failed"); xmlTextWriterPtr xml = xmlNewTextWriter(out); if (xml == NULL) - return std::string("xmlNewTextWriter failed"); + return mkfailure("xmlNewTextWriter failed"); const failable w = write(l, xml); xmlFreeTextWriter(xml); if (!hasValue(w)) { - return std::string(w); + return mkfailure(reason(w)); } return cx.accum; } -- cgit v1.2.3