2007-09-07 23:17:30 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <expat.h>
|
|
|
|
#include "xmlencodingspy.h"
|
|
|
|
|
|
|
|
XmlEncodingSpy::XmlEncodingSpy() :
|
2007-09-08 00:25:30 +02:00
|
|
|
d ( new EncodingData() )
|
2007-09-07 23:17:30 +02:00
|
|
|
{
|
2007-09-08 00:25:30 +02:00
|
|
|
XML_SetUserData ( p, d.get() );
|
|
|
|
XML_SetXmlDeclHandler ( p, xmldeclhandler );
|
|
|
|
XML_SetStartElementHandler ( p, start );
|
|
|
|
d->p = p;
|
2007-09-07 23:17:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
XmlEncodingSpy::~XmlEncodingSpy()
|
2007-09-08 00:25:30 +02:00
|
|
|
{}
|
2007-09-07 23:17:30 +02:00
|
|
|
|
2007-09-08 00:25:30 +02:00
|
|
|
void XMLCALL XmlEncodingSpy::xmldeclhandler (
|
|
|
|
void *data,
|
|
|
|
const XML_Char *version,
|
|
|
|
const XML_Char *encoding,
|
|
|
|
int standalone )
|
2007-09-07 23:17:30 +02:00
|
|
|
{
|
2007-09-08 00:25:30 +02:00
|
|
|
EncodingData *d;
|
|
|
|
d = ( EncodingData * ) data;
|
|
|
|
d->encoding = ( encoding ) ? encoding : "UTF-8";
|
2007-09-07 23:17:30 +02:00
|
|
|
}
|
|
|
|
|
2007-09-08 00:25:30 +02:00
|
|
|
void XMLCALL XmlEncodingSpy::start (
|
|
|
|
void *data,
|
|
|
|
const XML_Char *el,
|
|
|
|
const XML_Char **attr )
|
2007-09-07 23:17:30 +02:00
|
|
|
{
|
2007-09-08 00:25:30 +02:00
|
|
|
EncodingData *d;
|
|
|
|
d = ( EncodingData * ) data;
|
2007-09-07 23:17:30 +02:00
|
|
|
|
2007-09-08 00:25:30 +02:00
|
|
|
if ( !d->encoding.size() )
|
|
|
|
d->encoding = "UTF-8";
|
2007-09-07 23:17:30 +02:00
|
|
|
|
2007-09-08 00:25:30 +02:00
|
|
|
XML_StopParser ( d->p, false );
|
2007-09-07 23:17:30 +02:00
|
|
|
}
|