Improved encoding handling

This commit is contained in:
Zane U. Ji 2014-04-13 23:16:04 +08:00
parent 17f79c10c0
commit 8216a56d1e
29 changed files with 117 additions and 114 deletions

View File

@ -26,8 +26,11 @@
using namespace std; using namespace std;
HouseStyleReader::HouseStyleReader ( HouseStyleReader::HouseStyleReader (
map<string, map<string, set<string> > > &m map<string, map<string, set<string> > > &m
) : WrapExpat ( true ), ud ( new HouseStyleReaderData() ) , const char *encoding /*= NULL*/
)
: WrapExpat ( encoding, true )
, ud ( new HouseStyleReaderData() )
{ {
ud->setState ( STATE_UNKNOWN ); ud->setState ( STATE_UNKNOWN );
ud->depth = ud->cutoffDepth = 0; ud->depth = ud->cutoffDepth = 0;

View File

@ -43,7 +43,8 @@ class HouseStyleReader : public WrapExpat
{ {
public: public:
HouseStyleReader ( HouseStyleReader (
map<string, map<string, set<string> > > &m map<string, map<string, set<string> > > &m,
const char *encoding = NULL
); );
virtual ~HouseStyleReader(); virtual ~HouseStyleReader();
void getNodeVector ( vector<pair<string, unsigned> > &v ); void getNodeVector ( vector<pair<string, unsigned> > &v );

View File

@ -13,18 +13,18 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_VALIDATION_COMPLETED);
ValidationThread::ValidationThread ( ValidationThread::ValidationThread (
wxEvtHandler *handler, wxEvtHandler *handler,
const char *buffer, const char *utf8Buffer,
const wxString &system ) const wxString &system )
: wxThread ( wxTHREAD_JOINABLE ) : wxThread ( wxTHREAD_JOINABLE )
, mStopping ( false ) , mStopping ( false )
{ {
if ( buffer == NULL ) if ( utf8Buffer == NULL )
{ {
throw; throw;
} }
myEventHandler = handler; myEventHandler = handler;
myBuffer = buffer; myBuffer = utf8Buffer;
mySystem = system; mySystem = system;
myIsSucceeded = false; myIsSucceeded = false;
} }

View File

@ -13,7 +13,7 @@ class ValidationThread : public wxThread
public: public:
ValidationThread ( ValidationThread (
wxEvtHandler *handler, wxEvtHandler *handler,
const char *buffer, const char *utf8Buffer,
const wxString &system ); const wxString &system );
virtual void *Entry(); virtual void *Entry();
void setBuffer ( const char *buffer, const char *system ); void setBuffer ( const char *buffer, const char *system );

View File

@ -23,7 +23,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
WrapExpat::WrapExpat ( bool nameSpaceAware, const char *encoding ) WrapExpat::WrapExpat ( const char *encoding, bool nameSpaceAware )
{ {
p = ( nameSpaceAware ) ? XML_ParserCreateNS ( encoding, ( XML_Char ) ':' ) : XML_ParserCreate ( encoding ); p = ( nameSpaceAware ) ? XML_ParserCreateNS ( encoding, ( XML_Char ) ':' ) : XML_ParserCreate ( encoding );
if ( p == 0 ) if ( p == 0 )

View File

@ -32,7 +32,7 @@ using namespace std;
class WrapExpat class WrapExpat
{ {
public: public:
WrapExpat ( bool nameSpaceAware = false, const char *encoding = NULL ); WrapExpat ( const char *encoding = NULL, bool nameSpaceAware = false );
virtual ~WrapExpat(); virtual ~WrapExpat();
bool parse ( const string &buffer, bool isFinal = true ); bool parse ( const string &buffer, bool isFinal = true );
bool parse ( const char *buffer, size_t size, bool isFinal = true ); bool parse ( const char *buffer, size_t size, bool isFinal = true );

View File

@ -27,8 +27,10 @@
XmlAssociateDtd::XmlAssociateDtd ( XmlAssociateDtd::XmlAssociateDtd (
const std::string& path, const std::string& path,
const std::string& publicIdentifier, const std::string& publicIdentifier,
size_t size ) : const char *encoding,
d ( new DtdData() ) size_t size )
: WrapExpat ( encoding )
, d ( new DtdData() )
{ {
d->buffer.reserve ( size ); d->buffer.reserve ( size );
d->path = path; d->path = path;

View File

@ -38,6 +38,7 @@ class XmlAssociateDtd : public WrapExpat
XmlAssociateDtd ( XmlAssociateDtd (
const std::string& path = "", const std::string& path = "",
const std::string& publicIdentifier = "", const std::string& publicIdentifier = "",
const char *encoding = NULL,
size_t size = BUFSIZ ); size_t size = BUFSIZ );
virtual ~XmlAssociateDtd(); virtual ~XmlAssociateDtd();
std::string getBuffer() std::string getBuffer()

View File

@ -29,8 +29,10 @@
XmlAssociateXsd::XmlAssociateXsd ( XmlAssociateXsd::XmlAssociateXsd (
const std::string& path, const std::string& path,
size_t size ) : const char *encoding,
d ( new AssociateXsdData() ) size_t size )
: WrapExpat ( encoding )
, d ( new AssociateXsdData() )
{ {
d->buffer.reserve ( size ); d->buffer.reserve ( size );
d->path = path; d->path = path;

View File

@ -40,6 +40,7 @@ class XmlAssociateXsd : public WrapExpat
public: public:
XmlAssociateXsd ( XmlAssociateXsd (
const std::string& path = "", const std::string& path = "",
const char *encoding = NULL,
size_t size = BUFSIZ ); size_t size = BUFSIZ );
virtual ~XmlAssociateXsd(); virtual ~XmlAssociateXsd();
std::string getBuffer() std::string getBuffer()

View File

@ -24,8 +24,12 @@
#include <cstring> #include <cstring>
#include "xmlassociatexsl.h" #include "xmlassociatexsl.h"
XmlAssociateXsl::XmlAssociateXsl ( const std::string& path, size_t size ) : XmlAssociateXsl::XmlAssociateXsl (
d ( new XslData() ) const std::string& path,
const char *encoding,
size_t size )
: WrapExpat ( encoding )
, d ( new XslData() )
{ {
d->buffer.reserve ( size ); d->buffer.reserve ( size );
d->path = path; d->path = path;

View File

@ -38,6 +38,7 @@ class XmlAssociateXsl : public WrapExpat
public: public:
XmlAssociateXsl ( XmlAssociateXsl (
const std::string& path = "", const std::string& path = "",
const char *encoding = NULL,
size_t size = BUFSIZ ); size_t size = BUFSIZ );
virtual ~XmlAssociateXsl(); virtual ~XmlAssociateXsl();
std::string getBuffer() std::string getBuffer()

View File

@ -1354,23 +1354,16 @@ void MyFrame::OnCheckWellformedness ( wxCommandEvent& event )
if ( utf8Buffer.empty() ) if ( utf8Buffer.empty() )
return; return;
// handle unusual encodings
if ( !XmlEncodingHandler::setUtf8 ( utf8Buffer ) )
{
encodingMessage();
return;
}
doc->clearErrorIndicators(); doc->clearErrorIndicators();
statusProgress ( _ ( "Parse in progress..." ) ); statusProgress ( _ ( "Parse in progress..." ) );
// check for well-formedness // check for well-formedness
auto_ptr<WrapExpat> we ( new WrapExpat() ); WrapExpat we ( "UTF-8" );
if ( !we->parse ( utf8Buffer.c_str() ) ) if ( !we.parse ( utf8Buffer ) )
{ {
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
messagePane ( we->getLastError(), CONST_WARNING ); messagePane ( we.getLastError(), CONST_WARNING );
std::pair<int, int> posPair = we->getErrorPosition(); std::pair<int, int> posPair = we.getErrorPosition();
-- ( posPair.first ); -- ( posPair.first );
int cursorPos = int cursorPos =
doc->PositionFromLine ( posPair.first ); doc->PositionFromLine ( posPair.first );
@ -3902,14 +3895,9 @@ void MyFrame::OnValidateSchema ( wxCommandEvent& event )
{ {
std::string rawBuffer; std::string rawBuffer;
getRawText ( doc, rawBuffer ); getRawText ( doc, rawBuffer );
if ( !XmlEncodingHandler::setUtf8 ( rawBuffer ) ) XmlSchemaLocator xsl ( "UTF-8" );
{ xsl.parse ( rawBuffer.c_str() );
encodingMessage(); if ( ( xsl.getSchemaLocation() ) . empty() )
return;
}
auto_ptr<XmlSchemaLocator> xsl ( new XmlSchemaLocator() );
xsl->parse ( rawBuffer.c_str() );
if ( ( xsl->getSchemaLocation() ) . empty() )
{ {
OnValidateDTD ( event ); OnValidateDTD ( event );
return; return;
@ -3966,11 +3954,6 @@ void MyFrame::OnCreateSchema ( wxCommandEvent& event )
std::string rawBufferUtf8; std::string rawBufferUtf8;
getRawText ( doc, rawBufferUtf8 ); getRawText ( doc, rawBufferUtf8 );
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8 ) )
{
encodingMessage();
return;
}
const static wxString types[] = { _ ( "W3C Schema" ), _ ( "DTD" ) }; const static wxString types[] = { _ ( "W3C Schema" ), _ ( "DTD" ) };
const static wxString message = _ ( "Please choose a shema type"); const static wxString message = _ ( "Please choose a shema type");
@ -3981,11 +3964,11 @@ void MyFrame::OnCreateSchema ( wxCommandEvent& event )
Grammar::GrammarType type = ( dlg.GetSelection() == 0 ) ? Grammar::GrammarType type = ( dlg.GetSelection() == 0 ) ?
Grammar::SchemaGrammarType : Grammar::DTDGrammarType; Grammar::SchemaGrammarType : Grammar::DTDGrammarType;
std::auto_ptr<XmlSchemaGenerator> gen ( new XmlSchemaGenerator() ); XmlSchemaGenerator gen;
const wxString &schema = gen->generate(type, doc->getFullFileName(), const wxString &schema = gen.generate(type, doc->getFullFileName(),
rawBufferUtf8.c_str(), rawBufferUtf8.size() ); rawBufferUtf8.c_str(), rawBufferUtf8.size(), _T ( "UTF-8" ) );
if (schema.IsEmpty()) { if (schema.IsEmpty()) {
messagePane ( gen->getLastError(), CONST_WARNING ); messagePane ( gen.getLastError(), CONST_WARNING );
return; return;
} }
newDocument ( schema ); newDocument ( schema );
@ -4089,7 +4072,7 @@ void MyFrame::OnXslt ( wxCommandEvent& event )
int id = event.GetId(); int id = event.GetId();
if ( id == ID_XSLT ) if ( id == ID_XSLT )
{ {
XslLocator xl; XslLocator xl ( "UTF-8" );
xl.parse ( rawBufferUtf8 ); xl.parse ( rawBufferUtf8 );
std::string location = xl.getXslLocation(); std::string location = xl.getXslLocation();
@ -4211,12 +4194,6 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
std::string encoding = XmlEncodingHandler::get ( rawBufferUtf8 ); std::string encoding = XmlEncodingHandler::get ( rawBufferUtf8 );
if ( !XmlEncodingHandler::setUtf8 ( rawBufferUtf8, true ) )
{
encodingMessage();
return;
}
statusProgress ( _ ( "Pretty-printing in progress..." ) ); statusProgress ( _ ( "Pretty-printing in progress..." ) );
wxString fileName = doc->getFullFileName(); wxString fileName = doc->getFullFileName();
@ -4242,14 +4219,6 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
CONST_STOP ); CONST_STOP );
else else
{ {
/*
if (encoding != "UTF-8")
{
std::string output = getEncodedBuffer(rawBufferUtf8, encoding);
if (!output.empty())
rawBufferUtf8 = output;
}
*/
if ( encoding != "UTF-8" && !encoding.empty() ) if ( encoding != "UTF-8" && !encoding.empty() )
{ {
XmlEncodingHandler::set ( rawBufferUtf8, encoding ); XmlEncodingHandler::set ( rawBufferUtf8, encoding );
@ -4584,7 +4553,7 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
try try
{ {
getRawText ( doc, utf8Buffer ); getRawText ( doc, utf8Buffer );
XmlEncodingSpy es; XmlEncodingSpy es ( "UTF-8" );
es.parse ( utf8Buffer ); es.parse ( utf8Buffer );
encoding = es.getEncoding(); encoding = es.getEncoding();
wideEncoding = wxString ( encoding.c_str(), wxConvUTF8 ); wideEncoding = wxString ( encoding.c_str(), wxConvUTF8 );
@ -4629,13 +4598,13 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
} }
else if ( encoding == "UTF-8" ) else if ( encoding == "UTF-8" )
{ {
auto_ptr<WrapExpat> we ( new WrapExpat() ); WrapExpat we ( "UTF-8" );
if ( !we->parse ( utf8Buffer ) ) if ( !we.parse ( utf8Buffer ) )
{ {
//if ( we->isEncodingError() ) //if ( we->isEncodingError() )
// ; // ;
messagePane ( we->getLastError(), CONST_WARNING ); messagePane ( we.getLastError(), CONST_WARNING );
} }
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml ); success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
if ( success ) if ( success )
@ -5786,15 +5755,14 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
std::string utf8Buffer; std::string utf8Buffer;
getRawText ( doc, utf8Buffer ); getRawText ( doc, utf8Buffer );
std::string origEncoding = XmlEncodingHandler::get ( utf8Buffer ); std::string origEncoding = XmlEncodingHandler::get ( utf8Buffer );
XmlEncodingHandler::setUtf8 ( utf8Buffer, true ); WrapExpat wellformedparser ( "UTF-8" );
std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() ); if ( !wellformedparser.parse ( utf8Buffer ) )
if ( !wellformedparser->parse ( utf8Buffer ) )
{ {
wxString message; wxString message;
message.Printf ( message.Printf (
_ ( "Cannot associate %s: %s" ), _ ( "Cannot associate %s: %s" ),
type.c_str(), type.c_str(),
wellformedparser->getLastError().c_str() ); wellformedparser.getLastError().c_str() );
messagePane ( message, CONST_STOP ); messagePane ( message, CONST_STOP );
return; return;
} }
@ -5862,30 +5830,29 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
if ( id == ID_ASSOCIATE_W3C_SCHEMA ) if ( id == ID_ASSOCIATE_W3C_SCHEMA )
{ {
std::auto_ptr<XmlAssociateXsd> parser ( new XmlAssociateXsd ( utf8Path ) ); XmlAssociateXsd parser ( utf8Path, "UTF-8" );
if ( !parser->parse ( utf8Buffer ) ) if ( !parser.parse ( utf8Buffer ) )
return; return;
modifiedBuffer = parser->getBuffer(); modifiedBuffer = parser.getBuffer();
} }
else if ( id == ID_ASSOCIATE_DTD_SYSTEM || id == ID_ASSOCIATE_DTD_PUBLIC ) else if ( id == ID_ASSOCIATE_DTD_SYSTEM || id == ID_ASSOCIATE_DTD_PUBLIC )
{ {
std::auto_ptr<XmlAssociateDtd> parser ( new XmlAssociateDtd ( XmlAssociateDtd parser ( utf8Path,
utf8Path, ( auxiliaryBox ) ? ( const char * ) aux.mb_str ( wxConvUTF8 ) : "", "UTF-8" );
( auxiliaryBox ) ? ( const char * ) aux.mb_str ( wxConvUTF8 ) : "" ) ); if ( !parser.parse ( utf8Buffer ) )
if ( !parser->parse ( utf8Buffer ) )
return; return;
modifiedBuffer = parser->getBuffer(); modifiedBuffer = parser.getBuffer();
} }
else if ( id == ID_ASSOCIATE_XSL ) else if ( id == ID_ASSOCIATE_XSL )
{ {
std::auto_ptr<XmlAssociateXsl> parser ( new XmlAssociateXsl ( XmlAssociateXsl parser( utf8Path, "UTF-8" );
utf8Path ) ); if ( !parser.parse ( utf8Buffer ) )
if ( !parser->parse ( utf8Buffer ) )
return; return;
modifiedBuffer = parser->getBuffer(); modifiedBuffer = parser.getBuffer();
} }
else else
return; return;
XmlEncodingHandler::set ( modifiedBuffer, origEncoding ); XmlEncodingHandler::set ( modifiedBuffer, origEncoding );
doc->SetTextRaw ( modifiedBuffer.c_str() ); doc->SetTextRaw ( modifiedBuffer.c_str() );
doc->SetFocus(); doc->SetFocus();

View File

@ -1034,29 +1034,24 @@ void XmlCtrl::adjustNoColumnWidth()
void XmlCtrl::updatePromptMaps() void XmlCtrl::updatePromptMaps()
{ {
wxString buffer = GetText(); std::string bufferUtf8 = myGetTextRaw();
std::string bufferUtf8;
bufferUtf8 = ( const char * ) buffer.mb_str ( wxConvUTF8 );
XmlEncodingHandler::setUtf8 ( bufferUtf8, true );
updatePromptMaps ( bufferUtf8.c_str(), bufferUtf8.size() ); updatePromptMaps ( bufferUtf8.c_str(), bufferUtf8.size() );
} }
void XmlCtrl::updatePromptMaps ( const char *buffer, size_t bufferLen ) void XmlCtrl::updatePromptMaps ( const char *utf8Buffer, size_t bufferLen )
{ {
attributeMap.clear(); attributeMap.clear();
elementMap.clear(); elementMap.clear();
elementStructureMap.clear(); elementStructureMap.clear();
std::auto_ptr<XmlPromptGenerator> xpg ( new XmlPromptGenerator ( XmlPromptGenerator xpg ( basePath, auxPath, "UTF-8" );
basePath, xpg.parse ( utf8Buffer, bufferLen );
auxPath ) ); xpg.getAttributeMap ( attributeMap );
xpg->parse ( buffer, bufferLen ); xpg.getRequiredAttributeMap ( requiredAttributeMap );
xpg->getAttributeMap ( attributeMap ); xpg.getElementMap ( elementMap );
xpg->getRequiredAttributeMap ( requiredAttributeMap ); xpg.getElementStructureMap ( elementStructureMap );
xpg->getElementMap ( elementMap ); xpg.getEntitySet ( entitySet );
xpg->getElementStructureMap ( elementStructureMap ); grammarFound = xpg.getGrammarFound();
xpg->getEntitySet ( entitySet );
grammarFound = xpg->getGrammarFound();
entitySet.insert ( _T ( "amp" ) ); entitySet.insert ( _T ( "amp" ) );
entitySet.insert ( _T ( "apos" ) ); entitySet.insert ( _T ( "apos" ) );
entitySet.insert ( _T ( "quot" ) ); entitySet.insert ( _T ( "quot" ) );
@ -1954,8 +1949,6 @@ bool XmlCtrl::backgroundValidate()
std::string bufferUtf8 = myGetTextRaw(); std::string bufferUtf8 = myGetTextRaw();
XmlEncodingHandler::setUtf8( bufferUtf8, true );
return backgroundValidate ( return backgroundValidate (
bufferUtf8.c_str(), bufferUtf8.c_str(),
basePath, basePath,

View File

@ -115,7 +115,7 @@ class XmlCtrl: public wxStyledTextCtrl
bool zoomOnly = false ); bool zoomOnly = false );
void applyVisibilityState ( int state = SHOW_TAGS ); void applyVisibilityState ( int state = SHOW_TAGS );
void updatePromptMaps(); void updatePromptMaps();
void updatePromptMaps ( const char *buffer, size_t bufferLen ); void updatePromptMaps ( const char *utf8Buffer, size_t bufferLen );
void adjustCursor(); void adjustCursor();
void adjustSelection(); void adjustSelection();
void foldAll(); void foldAll();

View File

@ -23,8 +23,9 @@
#include <expat.h> #include <expat.h>
#include "xmlencodingspy.h" #include "xmlencodingspy.h"
XmlEncodingSpy::XmlEncodingSpy() : XmlEncodingSpy::XmlEncodingSpy ( const char *encoding )
d ( new EncodingData() ) : WrapExpat ( encoding )
, d ( new EncodingData() )
{ {
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );
XML_SetXmlDeclHandler ( p, xmldeclhandler ); XML_SetXmlDeclHandler ( p, xmldeclhandler );

View File

@ -34,7 +34,7 @@ struct EncodingData : public ParserData
class XmlEncodingSpy : public WrapExpat class XmlEncodingSpy : public WrapExpat
{ {
public: public:
XmlEncodingSpy(); XmlEncodingSpy ( const char *encoding = NULL );
virtual ~XmlEncodingSpy(); virtual ~XmlEncodingSpy();
std::string getEncoding() std::string getEncoding()
{ {

View File

@ -23,7 +23,9 @@
#include <expat.h> #include <expat.h>
#include "xmlparseschemans.h" #include "xmlparseschemans.h"
XmlParseSchemaNs::XmlParseSchemaNs() : WrapExpat ( false ), d ( new ParseSchemaNsData() ) XmlParseSchemaNs::XmlParseSchemaNs()
: WrapExpat ( NULL, false )
, d ( new ParseSchemaNsData() )
{ {
d->p = p; // set parser for XML_StopParser call d->p = p; // set parser for XML_StopParser call
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );

View File

@ -45,7 +45,11 @@ using namespace xercesc;
XmlPromptGenerator::XmlPromptGenerator ( XmlPromptGenerator::XmlPromptGenerator (
const wxString& basePath, const wxString& basePath,
const wxString& auxPath ) : d ( new PromptGeneratorData() ) const wxString& auxPath,
const char *encoding
)
: WrapExpat ( encoding )
, d ( new PromptGeneratorData() )
{ {
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );
d->p = p; d->p = p;

View File

@ -53,7 +53,8 @@ class XmlPromptGenerator : public WrapExpat
public: public:
XmlPromptGenerator ( XmlPromptGenerator (
const wxString& basePath = wxEmptyString, const wxString& basePath = wxEmptyString,
const wxString& auxPath = wxEmptyString ); const wxString& auxPath = wxEmptyString,
const char *encoding = NULL );
virtual ~XmlPromptGenerator(); virtual ~XmlPromptGenerator();
void getAttributeMap ( void getAttributeMap (
std::map<wxString, std::map<wxString, std::set<wxString> > > std::map<wxString, std::map<wxString, std::set<wxString> > >

View File

@ -40,8 +40,13 @@ XmlSchemaGenerator::~XmlSchemaGenerator()
{ {
} }
const wxString &XmlSchemaGenerator::generate ( Grammar::GrammarType grammarType, const wxString &XmlSchemaGenerator::generate (
const wxString &filepath, const char *buffer, size_t len ) Grammar::GrammarType grammarType
, const wxString &filepath
, const char *buffer
, size_t len
, const wxString &encoding
)
{ {
mGrammarType = grammarType; mGrammarType = grammarType;
mElements.clear(); mElements.clear();
@ -56,6 +61,9 @@ const wxString &XmlSchemaGenerator::generate ( Grammar::GrammarType grammarType,
MemBufInputSource source ( ( const XMLByte * ) buffer, len, MemBufInputSource source ( ( const XMLByte * ) buffer, len,
filepath.mb_str( wxConvLocal ) ); filepath.mb_str( wxConvLocal ) );
if ( !wxIsEmpty ( encoding ) )
source.setEncoding ( (const XMLCh *)
WrapXerces::toString ( encoding ).GetData() );
try { try {
//XMLPlatformUtils::fgSSE2ok = false; //XMLPlatformUtils::fgSSE2ok = false;
parser->parse ( source ); parser->parse ( source );

View File

@ -38,7 +38,8 @@ public:
virtual ~XmlSchemaGenerator(); virtual ~XmlSchemaGenerator();
const wxString &generate ( Grammar::GrammarType grammarType, const wxString &generate ( Grammar::GrammarType grammarType,
const wxString &filepath, const char *buffer, size_t len ); const wxString &filepath, const char *buffer, size_t len,
const wxString &encoding );
const wxString &getLastError() { return mLastError; } const wxString &getLastError() { return mLastError; }
static void addIndent ( wxString &str, size_t nIndent ) static void addIndent ( wxString &str, size_t nIndent )

View File

@ -24,8 +24,9 @@
#include <expat.h> #include <expat.h>
#include "xmlschemalocator.h" #include "xmlschemalocator.h"
XmlSchemaLocator::XmlSchemaLocator() : XmlSchemaLocator::XmlSchemaLocator ( const char *encoding )
WrapExpat ( true ), d ( new SchemaLocatorData() ) : WrapExpat ( encoding, true )
, d ( new SchemaLocatorData() )
{ {
d->parser = p; d->parser = p;
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );

View File

@ -34,7 +34,7 @@ struct SchemaLocatorData
class XmlSchemaLocator : public WrapExpat class XmlSchemaLocator : public WrapExpat
{ {
public: public:
XmlSchemaLocator(); XmlSchemaLocator ( const char *encoding );
virtual ~XmlSchemaLocator(); virtual ~XmlSchemaLocator();
std::string getSchemaLocation(); std::string getSchemaLocation();
private: private:

View File

@ -24,8 +24,13 @@
#include <expat.h> #include <expat.h>
#include "xmlschemaparser.h" #include "xmlschemaparser.h"
XmlSchemaParser::XmlSchemaParser ( PromptGeneratorData *data, bool nameSpaceAware ) : XmlSchemaParser::XmlSchemaParser (
WrapExpat ( nameSpaceAware ), d ( new SchemaParserData ) PromptGeneratorData *data,
const char *encoding,
bool nameSpaceAware
)
: WrapExpat ( encoding, nameSpaceAware )
, d ( new SchemaParserData )
{ {
d->promptData = data; d->promptData = data;
d->setState ( STATE_UNKNOWN ); d->setState ( STATE_UNKNOWN );

View File

@ -35,7 +35,10 @@ struct SchemaParserData : public ParserData
class XmlSchemaParser : public WrapExpat class XmlSchemaParser : public WrapExpat
{ {
public: public:
XmlSchemaParser ( PromptGeneratorData *data, bool nameSpaceAware ); XmlSchemaParser (
PromptGeneratorData *data,
const char *encoding,
bool nameSpaceAware );
virtual ~XmlSchemaParser(); virtual ~XmlSchemaParser();
enum { enum {
STATE_UNKNOWN, STATE_UNKNOWN,

View File

@ -23,7 +23,7 @@
#include "getword.h" #include "getword.h"
XmlWordCount::XmlWordCount ( const char *encoding ) XmlWordCount::XmlWordCount ( const char *encoding )
: WrapExpat ( false, encoding ) : WrapExpat ( encoding, false )
, wcd ( new WordCountData() ) , wcd ( new WordCountData() )
{ {
wcd->wordCount = 0; wcd->wordCount = 0;

View File

@ -24,7 +24,9 @@
#include <expat.h> #include <expat.h>
#include "xsllocator.h" #include "xsllocator.h"
XslLocator::XslLocator() : d ( new XslLocatorData() ) XslLocator::XslLocator ( const char *encoding )
: WrapExpat ( encoding )
, d ( new XslLocatorData() )
{ {
d->parser = p; d->parser = p;
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );

View File

@ -34,7 +34,7 @@ struct XslLocatorData : public ParserData
class XslLocator : public WrapExpat class XslLocator : public WrapExpat
{ {
public: public:
XslLocator(); XslLocator ( const char * encoding = NULL );
virtual ~XslLocator(); virtual ~XslLocator();
std::string getXslLocation(); std::string getXslLocation();
private: private: