Merge pull request #4 from sradomski/master

Proper CData support for libxml2 wrapper
This commit is contained in:
Jez Higgins 2013-08-18 14:17:15 -07:00
commit 379fa889e3
4 changed files with 98 additions and 3 deletions

View file

@ -130,7 +130,7 @@ class EventImpl : virtual public Arabica::DOM::Events::Event_impl<stringT, strin
#ifdef _WIN32
FILETIME tv;
GetSystemTimeAsFileTime(&tv);
time = (((uint64_t) tv.dwHighDateTime) << 32) + tv.dwLowDateTime;
time = (((__int64) tv.dwHighDateTime) << 32) + tv.dwLowDateTime;
time /= 10000;
#else
struct timeval tv;

View file

@ -91,6 +91,10 @@ dom_headers = DOM/SAX2DOM/SAX2DOM.hpp \
DOM/EntityReference.hpp \
DOM/Attr.hpp \
DOM/NodeList.hpp \
DOM/Simple/EventImpl.hpp \
DOM/Simple/EventTargetImpl.hpp \
DOM/Simple/MutationEventImpl.hpp \
DOM/Simple/DocumentEventImpl.hpp \
DOM/Simple/ProcessingInstructionImpl.hpp \
DOM/Simple/EntityReferenceImpl.hpp \
DOM/Simple/CharacterDataImpl.hpp \

View file

@ -48,6 +48,7 @@ class libxml2_base
virtual void SAXendDocument() = 0;
virtual void SAXlocator(xmlSAXLocatorPtr locator) = 0;
virtual void SAXcharacters(const xmlChar* ch, int len) = 0;
virtual void SAXcdata(const xmlChar* ch, int len) = 0;
virtual void SAXignorableWhitespace(const xmlChar* ch, int len) = 0;
virtual void SAXwarning(const std::string& warning) = 0;
virtual void SAXerror(const std::string& error) = 0;
@ -64,10 +65,13 @@ class libxml2_base
virtual xmlParserInputPtr SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId) = 0;
virtual xmlParserCtxtPtr parserContext() = 0;
virtual void SAXstartCdataSection() = 0;
virtual void SAXendCdataSection() = 0;
friend void lwit_startDocument(void* user_data);
friend void lwit_endDocument(void* user_data);
friend void lwit_characters(void *user_data, const xmlChar* ch, int len);
friend void lwit_cdata(void *user_data, const xmlChar* ch, int len);
friend void lwit_ignorableWhitespace(void *user_data, const xmlChar* ch, int len);
friend void lwit_locator(void* user_data, xmlSAXLocatorPtr locator);
friend void lwit_warning(void *user_data, const char* fmt, ...);
@ -91,6 +95,7 @@ void lwit_endDocument(void* user_data);
void lwit_startElement(void *user_data, const xmlChar* name, const xmlChar** attrs);
void lwit_endElement(void *user_data, const xmlChar* name);
void lwit_characters(void* user_data, const xmlChar* ch, int len);
void lwit_cdata(void* user_data, const xmlChar* ch, int len);
void lwit_ignorableWhitespace(void *user_data, const xmlChar* ch, int len);
void lwit_processingInstruction(void *user_data, const xmlChar* target, const xmlChar* data);
void lwit_comment(void *user_data, const xmlChar* comment);
@ -190,12 +195,15 @@ class libxml2_wrapper :
virtual void SAXendDocument();
virtual void SAXlocator(xmlSAXLocatorPtr locator) { locator_ = locator; }
virtual void SAXcharacters(const xmlChar* ch, int len);
virtual void SAXcdata(const xmlChar* ch, int len);
virtual void SAXignorableWhitespace(const xmlChar* ch, int len);
virtual void SAXwarning(const std::string& warning);
virtual void SAXerror(const std::string& error);
virtual void SAXfatalError(const std::string& fatal);
virtual void SAXprocessingInstruction(const xmlChar* target, const xmlChar* data);
virtual void SAXcomment(const xmlChar* comment);
virtual void SAXstartCdataSection();
virtual void SAXendCdataSection();
virtual void SAXstartElement(const xmlChar* name, const xmlChar** attrs);
virtual void SAXstartElementNoNS(const xmlChar* name, const xmlChar** attrs);
virtual void SAXendElement(const xmlChar* name);
@ -232,6 +240,7 @@ class libxml2_wrapper :
bool namespaces_;
bool prefixes_;
bool isInCData_;
string_type emptyString_;
const FeatureNames<string_type, string_adaptor> features_;
@ -251,6 +260,7 @@ libxml2_wrapper<string_type, T0, T1>::libxml2_wrapper() :
lexicalHandler_(0),
locator_(0),
parsing_(false),
isInCData_(false),
namespaces_(true),
prefixes_(true)
{
@ -477,6 +487,9 @@ void libxml2_wrapper<string_type, T0, T1>::parse(inputSourceT& source)
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXstartDocument()
{
if(isInCData_)
SAXendCdataSection();
if(contentHandler_)
contentHandler_->startDocument();
} // SAXstartDocument
@ -484,6 +497,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartDocument()
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXendDocument()
{
if(isInCData_)
SAXendCdataSection();
if(contentHandler_)
contentHandler_->endDocument();
} // SAXendDocument
@ -491,10 +507,20 @@ void libxml2_wrapper<string_type, T0, T1>::SAXendDocument()
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXcharacters(const xmlChar* ch, int len)
{
if(isInCData_)
SAXendCdataSection();
if(contentHandler_)
contentHandler_->characters(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXcharacters
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXcdata(const xmlChar* ch, int len)
{
if(contentHandler_)
contentHandler_->characters(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(ch), len));
} // SAXcdata
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXignorableWhitespace(const xmlChar* ch, int len)
{
@ -526,6 +552,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXfatalError(const std::string& fata
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXprocessingInstruction(const xmlChar* target, const xmlChar* data)
{
if(isInCData_)
SAXendCdataSection();
if(contentHandler_)
contentHandler_->processingInstruction(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(target)),
string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(data)));
@ -534,13 +563,42 @@ void libxml2_wrapper<string_type, T0, T1>::SAXprocessingInstruction(const xmlCha
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXcomment(const xmlChar* comment)
{
if(isInCData_)
SAXendCdataSection();
if(lexicalHandler_)
lexicalHandler_->comment(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(comment)));
} // SAXcomment
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXstartCdataSection()
{
if (isInCData_)
return;
isInCData_ = true;
if(lexicalHandler_)
lexicalHandler_->startCDATA();
} // startCdataSection
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXendCdataSection()
{
if (!isInCData_)
return;
if(lexicalHandler_)
lexicalHandler_->endCDATA();
isInCData_ = false;
} // endCdataSection
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXstartElement(const xmlChar* qName, const xmlChar** atts)
{
if(isInCData_)
SAXendCdataSection();
if(!contentHandler_)
return;
@ -613,6 +671,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartElementNoNS(const xmlChar* qN
{
SAX::AttributesImpl<string_type, string_adaptor> attributes;
if(isInCData_)
SAXendCdataSection();
if(atts && *atts != 0)
{
while(*atts != 0)
@ -634,6 +695,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXstartElementNoNS(const xmlChar* qN
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXendElement(const xmlChar* qName)
{
if(isInCData_)
SAXendCdataSection();
if(!contentHandler_)
return;
@ -656,6 +720,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXendElement(const xmlChar* qName)
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXendElementNoNS(const xmlChar* qName)
{
if(isInCData_)
SAXendCdataSection();
if(contentHandler_)
contentHandler_->endElement(emptyString_, emptyString_, string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(qName)));
} // SAXendElementNoNS
@ -663,6 +730,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXendElementNoNS(const xmlChar* qNam
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXnotationDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId)
{
if(isInCData_)
SAXendCdataSection();
if(dtdHandler_)
dtdHandler_->notationDecl(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(name)),
string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(publicId)),
@ -672,6 +742,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXnotationDecl(const xmlChar *name,
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXunparsedEntityDecl(const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName)
{
if(isInCData_)
SAXendCdataSection();
if(dtdHandler_)
dtdHandler_->unparsedEntityDecl(string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(name)),
string_adaptor::construct_from_utf8(reinterpret_cast<const char*>(publicId)),
@ -682,6 +755,9 @@ void libxml2_wrapper<string_type, T0, T1>::SAXunparsedEntityDecl(const xmlChar *
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXelementDecl(const xmlChar* name, int type, xmlElementContentPtr content)
{
if(isInCData_)
SAXendCdataSection();
if(!declHandler_)
return;
@ -766,6 +842,9 @@ void libxml2_wrapper<string_type, T0, T1>::convertXML_Content(std::ostream& os,
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXattributeDecl(const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree)
{
if(isInCData_)
SAXendCdataSection();
if(!declHandler_)
return;
@ -838,6 +917,9 @@ string_type libxml2_wrapper<string_type, T0, T1>::stringAttrEnum(xmlEnumeration
template<class string_type, class T0, class T1>
void libxml2_wrapper<string_type, T0, T1>::SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
{
if(isInCData_)
SAXendCdataSection();
if(!declHandler_)
return;

View file

@ -58,6 +58,15 @@ void lwit_characters(void* user_data, const xmlChar* ch, int len)
p->SAXcharacters(ch, len);
} // lwit_characters
void lwit_cdata(void* user_data, const xmlChar* ch, int len)
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
p->SAXstartCdataSection();
p->SAXcdata(ch, len);
// everyone else will call endCData if we are in cdata
// p->SAXendCdataSection();
} // lwit_cdata
void lwit_ignorableWhitespace(void *user_data, const xmlChar* ch, int len)
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
@ -193,7 +202,7 @@ static xmlSAXHandler saxHandler = {
lwit_error, // errorSAXFunc error;
lwit_fatalError, // fatalErrorSAXFunc fatalError;
0, // getParameterEntitySAXFunc getParameterEntity;
lwit_characters, // cdataBlockSAXFunc cdataBlock;
lwit_cdata, // cdataBlockSAXFunc cdataBlock;
0, // externalSubsetSAXFunc externalSubset;
0, // initialized;
/* The following fields are extensions available only on version 2 */