some work on implementing cdata section output, then realised it would probably be easier if I dropped a state machine in there

This commit is contained in:
jez 2009-03-31 20:00:26 +01:00
parent 75497467cf
commit f373a1d01b
4 changed files with 42 additions and 35 deletions

View file

@ -39,7 +39,7 @@ public:
namesp = namespace_->evaluateAsString(node, context.xpathContext());
else
{
QName qn = QName::createQName(name);
QName qn = QName::create(name);
if(!qn.prefix.empty())
{
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);

View file

@ -43,7 +43,7 @@ public:
namesp = namespace_->evaluateAsString(node, context.xpathContext());
else
{
QName qn = QName::createQName(name);
QName qn = QName::create(name);
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);
if(ns == namespaces_.end())
throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);

View file

@ -13,38 +13,45 @@ struct QName
std::string prefix;
std::string localName;
std::string namespaceURI;
std::string qname;
static QName createQName(const std::string& qName)
QName(const std::string& p,
const std::string& lN,
const std::string& uri) :
prefix(p),
localName(lN),
namespaceURI(uri),
qname(p.empty() ? lN : (p + ":" + lN))
{
} // QName
static QName create(const std::string& qName)
{
return create(qName, "");
} // create
static QName create(const std::string& qName, const std::string& namespaceURI)
{
if(!Arabica::XML::is_qname<Arabica::default_string_adaptor<std::string> >(qName))
throw SAX::SAXException("Bad name : " + qName);
static char COLON = Arabica::text::Unicode<char>::COLON;
QName qn;
std::string prefix;
std::string localName;
size_t colon = qName.find(COLON);
if(colon == std::string::npos)
qn.localName = qName;
localName = qName;
else
{
qn.prefix = qName.substr(0, colon);
qn.localName = qName.substr(colon+1);
prefix = qName.substr(0, colon);
localName = qName.substr(colon+1);
}
return qn;
} // createQName
static QName createQName(const std::string& qName, const std::string namespaceURI)
{
QName qn(createQName(qName));
qn.namespaceURI = namespaceURI;
if(!qn.prefix.empty() && qn.namespaceURI.empty())
throw SAX::SAXException("Undeclared prefix " + qn.prefix);
return qn;
} // createQName
}; // QName
return QName(prefix, localName, namespaceURI);
} // create
}; // struct QName
} // namespace XSLT
} // namespace Arabica

View file

@ -52,8 +52,8 @@ public:
bool start_element(const std::string& qName, const std::string& namespaceURI)
{
QName qn = QName::createQName(qName, namespaceURI);
return start_element(qn.prefix, qn.localName, qn.namespaceURI);
QName en = QName::create(qName, namespaceURI);
return start_element(en.prefix, en.localName, en.namespaceURI);
} // start_element
bool start_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
@ -68,8 +68,8 @@ public:
namespaceStack_.declareNamespace(prefix, namespaceURI);
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
name_ = (!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName;
namespaceURI_ = namespaceURI;
element_stack_.push(QName(mapped_prefix, localName, namespaceURI));
atts_.clear();
pending_element_ = true;
@ -80,8 +80,8 @@ public:
void end_element(const std::string& qName, const std::string& namespaceURI)
{
QName qn = QName::createQName(qName, namespaceURI);
end_element(qn.prefix, qn.localName, qn.namespaceURI);
QName en = QName::create(qName, namespaceURI);
end_element(en.prefix, en.localName, en.namespaceURI);
} // end_element
void end_element(const std::string& prefix, const std::string& localName, const std::string& namespaceURI)
@ -95,6 +95,7 @@ public:
{
std::string mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
do_end_element((!mapped_prefix.empty()) ? mapped_prefix + ':' + localName : localName, namespaceURI);
element_stack_.pop();
} // end_element
namespaceStack_.popScope();
@ -102,7 +103,7 @@ public:
void start_attribute(const std::string& qName, const std::string& namespaceURI)
{
QName qn = QName::createQName(qName, namespaceURI);
QName qn = QName::create(qName, namespaceURI);
start_attribute(qn.prefix, qn.localName, qn.namespaceURI);
} // start_attribute
@ -208,7 +209,7 @@ public:
flush_element();
name_ = target;
target_ = target;
} // start_processing_instruction
void end_processing_instruction()
@ -219,7 +220,7 @@ public:
if(!text_mode_)
{
std::string data = escape(buffer_.str(), "?>", "? >");
do_processing_instruction(name_, data);
do_processing_instruction(target_, data);
} // if ...
} // end_processing_instruction
@ -306,8 +307,7 @@ private:
if(want_decs)
addNamespaceDeclarations();
do_start_element(name_, namespaceURI_, atts_);
do_start_element(element_stack_.top().qname, element_stack_.top().namespaceURI, atts_);
pending_element_ = false;
} // flush_element
@ -336,8 +336,8 @@ private:
int buffering_;
bool pending_element_;
int pending_attribute_;
std::string name_;
std::string namespaceURI_;
std::stack<QName> element_stack_;
std::string target_;
SAX::AttributesImpl<std::string, Arabica::default_string_adaptor<std::string> > atts_;
std::stringstream buffer_;
bool text_mode_;