mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
text
This commit is contained in:
parent
0d3a91876a
commit
3743972b0a
3 changed files with 24 additions and 22 deletions
|
@ -67,7 +67,7 @@ public:
|
|||
for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
|
||||
if(!Arabica::XML::is_space(*i))
|
||||
{
|
||||
container_->add_item(new Text(ch));
|
||||
container_->add_item(new Text<std::string, Arabica::default_string_adaptor<std::string> >(ch));
|
||||
return;
|
||||
} // if ...
|
||||
} // characters
|
||||
|
@ -153,7 +153,7 @@ const ChildElement* AllowedChildren()
|
|||
{ "message", CreateHandler<MessageHandler>},
|
||||
{ "number", CreateHandler<NotImplementedYetHandler>},
|
||||
{ "processing-instruction", CreateHandler<ProcessingInstructionHandler> },
|
||||
{ "text", CreateHandler<TextHandler> },
|
||||
{ "text", CreateHandler<TextHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
|
||||
{ "value-of", CreateHandler<ValueOfHandler> },
|
||||
{ "variable", CreateHandler<VariableHandler<Variable> > },
|
||||
{ 0, 0 }
|
||||
|
|
|
@ -8,49 +8,50 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
class TextHandler : public SAX::DefaultHandler<std::string>
|
||||
template<class string_type, class string_adaptor>
|
||||
class TextHandler : public SAX::DefaultHandler<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
TextHandler(CompilationContext<std::string>& context) :
|
||||
TextHandler(CompilationContext<string_type, string_adaptor>& context) :
|
||||
context_(context),
|
||||
text_(0)
|
||||
{
|
||||
} // TextHandler
|
||||
|
||||
virtual void startElement(const std::string& /* namespaceURI */,
|
||||
const std::string& /* localName */,
|
||||
const std::string& qName,
|
||||
const SAX::Attributes<std::string>& atts)
|
||||
virtual void startElement(const string_type& /* namespaceURI */,
|
||||
const string_type& /* localName */,
|
||||
const string_type& qName,
|
||||
const SAX::Attributes<string_type, string_adaptor>& atts)
|
||||
{
|
||||
if(text_ == 0)
|
||||
{
|
||||
static const ValueRule rules[] = { { "disable-output-escaping", false, No, AllowedYesNo },
|
||||
{ 0, false, 0, 0 } };
|
||||
text_ = new Text(gatherAttributes(qName, atts, rules)["disable-output-escaping"] == Yes);
|
||||
text_ = new Text<string_type, string_adaptor>(gatherAttributes(qName, atts, rules)["disable-output-escaping"] == Yes);
|
||||
return;
|
||||
} // if(text_ == 0)
|
||||
|
||||
throw SAX::SAXException(qName + " can not contain elements");
|
||||
} // startElement
|
||||
|
||||
virtual void endElement(const std::string& /* namespaceURI */,
|
||||
const std::string& /* localName */,
|
||||
const std::string& /* qName */)
|
||||
virtual void endElement(const string_type& /* namespaceURI */,
|
||||
const string_type& /* localName */,
|
||||
const string_type& /* qName */)
|
||||
{
|
||||
text_->set(buffer_);
|
||||
context_.parentContainer().add_item(text_);
|
||||
context_.pop();
|
||||
} // endElement
|
||||
|
||||
virtual void characters(const std::string& ch)
|
||||
virtual void characters(const string_type& ch)
|
||||
{
|
||||
buffer_ += ch;
|
||||
} // characters
|
||||
|
||||
private:
|
||||
CompilationContext<std::string>& context_;
|
||||
Text* text_;
|
||||
std::string buffer_;
|
||||
CompilationContext<string_type, string_adaptor>& context_;
|
||||
Text<string_type, string_adaptor>* text_;
|
||||
string_type buffer_;
|
||||
}; // class TextHandler
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
class Text : public Item
|
||||
{
|
||||
public:
|
||||
|
@ -16,16 +17,16 @@ public:
|
|||
{
|
||||
} // Text
|
||||
|
||||
Text(const std::string& text) :
|
||||
Text(const string_type& text) :
|
||||
text_(text),
|
||||
disable_(false)
|
||||
{
|
||||
} // Text
|
||||
|
||||
void set(const std::string& text) { text_ = text; }
|
||||
void set(const string_type& text) { text_ = text; }
|
||||
|
||||
virtual void execute(const DOM::Node<std::string>& /* node */,
|
||||
ExecutionContext& context) const
|
||||
virtual void execute(const DOM::Node<string_type, string_adaptor>& /* node */,
|
||||
ExecutionContext& context) const
|
||||
{
|
||||
if(disable_)
|
||||
context.sink().disableOutputEscaping(true);
|
||||
|
@ -37,8 +38,8 @@ public:
|
|||
} // execute
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
bool disable_;
|
||||
string_type text_;
|
||||
const bool disable_;
|
||||
}; // class Text
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
Loading…
Reference in a new issue