Replaced std::string with wxString

This commit is contained in:
Zane U. Ji 2013-12-15 22:21:31 +08:00
parent dff2513b0d
commit 80229a3686
4 changed files with 22 additions and 36 deletions

View File

@ -128,8 +128,7 @@ bool WrapDaisy::run (
if ( !success ) if ( !success )
{ {
std::string stdError = wrapLibxml.getLastError(); error = wrapLibxml.getLastError();
error = wxString ( stdError.c_str(), wxConvUTF8, stdError.size() );
return false; return false;
} }

View File

@ -103,7 +103,6 @@ void WrapLibxml::Init ( const wxString &catalogPath ) throw()
WrapLibxml::WrapLibxml ( bool netAccessParameter ) WrapLibxml::WrapLibxml ( bool netAccessParameter )
: netAccess ( netAccessParameter ) : netAccess ( netAccessParameter )
, errorLine ( 0 )
{ {
WrapLibxml::Init(); WrapLibxml::Init();
} }
@ -500,8 +499,8 @@ bool WrapLibxml::xslt (
} while ( false ); } while ( false );
xmlFreeDoc ( doc ); xmlFreeDoc ( doc );
xmlFreeDoc ( res );
xmlFreeParserCtxt ( ctxt ); xmlFreeParserCtxt ( ctxt );
xmlFreeDoc ( res );
xsltFreeStylesheet ( cur ); xsltFreeStylesheet ( cur );
return ret; return ret;
@ -592,33 +591,28 @@ int WrapLibxml::saveEncodingFromFile (
// ensure entity warnings are treated as errors! // ensure entity warnings are treated as errors!
if ( !getLastError().empty() ) if ( !getLastError().empty() )
return -1; result = -1;
xmlFreeDoc ( docPtr ); xmlFreeDoc ( docPtr );
xmlFreeParserCtxt ( ctxt ); xmlFreeParserCtxt ( ctxt );
return result; return result;
} }
std::string WrapLibxml::getLastError() wxString WrapLibxml::getLastError()
{ {
xmlErrorPtr err = xmlGetLastError(); xmlErrorPtr err = xmlGetLastError();
if ( !err ) if ( !err )
{
return nonParserError; return nonParserError;
}
std::stringstream ss; wxString error ( err->message, wxConvLocal );
ss << "Error at line ";
ss << err->line;
if ( err->int2 ) if ( err->int2 )
{ return wxString::Format ( _("Error at line %d, column %d: %s"),
ss << ", column "; err->line, err->int2, error.c_str() );
ss << err->int2;
} return wxString::Format ( _("Error at line %d: %s"),
ss << ": "; err->line, error.c_str() );
ss << err->message;
return ss.str();
} }
std::pair<int, int> WrapLibxml::getErrorPosition() std::pair<int, int> WrapLibxml::getErrorPosition()

View File

@ -78,7 +78,7 @@ class WrapLibxml
const char *utf8DocBuf, const char *utf8DocBuf,
size_t utf8DocBufSize, size_t utf8DocBufSize,
const wxString &docUrl ); const wxString &docUrl );
std::string getLastError(); wxString getLastError();
std::pair<int, int> getErrorPosition(); std::pair<int, int> getErrorPosition();
std::string getOutput(); std::string getOutput();
int saveEncoding ( int saveEncoding (
@ -94,8 +94,8 @@ class WrapLibxml
const wxString &systemId ); const wxString &systemId );
private: private:
bool netAccess; bool netAccess;
std::string output, nonParserError; std::string output;
int errorLine; wxString nonParserError;
}; };
#endif #endif

View File

@ -3781,8 +3781,7 @@ void MyFrame::OnValidateDTD ( wxCommandEvent& event )
wxString fname = doc->getFullFileName(); wxString fname = doc->getFullFileName();
if ( !wl->validate ( doc->myGetTextRaw(), fname ) ) if ( !wl->validate ( doc->myGetTextRaw(), fname ) )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
messagePane ( wideError, CONST_WARNING ); messagePane ( wideError, CONST_WARNING );
@ -3858,8 +3857,7 @@ void MyFrame::validateRelaxNG (
if ( !wl->validateRelaxNG ( schemaName, doc->myGetTextRaw(), fileName ) ) if ( !wl->validateRelaxNG ( schemaName, doc->myGetTextRaw(), fileName ) )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
std::pair<int, int> posPair = wl->getErrorPosition(); std::pair<int, int> posPair = wl->getErrorPosition();
@ -4060,8 +4058,7 @@ void MyFrame::OnXPath ( wxCommandEvent& event )
if ( !success ) if ( !success )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
if ( !wideError.empty() ) if ( !wideError.empty() )
wideError.Prepend ( _T ( ": " ) ); wideError.Prepend ( _T ( ": " ) );
wideError.Prepend ( _ ( "Cannot evaluate XPath" ) ); wideError.Prepend ( _ ( "Cannot evaluate XPath" ) );
@ -4189,8 +4186,7 @@ void MyFrame::OnXslt ( wxCommandEvent& event )
wxString fileName = doc->getFullFileName(); wxString fileName = doc->getFullFileName();
if ( !wl->xslt ( path, rawBufferUtf8, fileName ) ) if ( !wl->xslt ( path, rawBufferUtf8, fileName ) )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
wideError.Prepend ( _ ( "Cannot transform: " ) ); wideError.Prepend ( _ ( "Cannot transform: " ) );
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
messagePane ( wideError, CONST_WARNING ); messagePane ( wideError, CONST_WARNING );
@ -4238,8 +4234,7 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
if ( !wl->parse ( rawBufferUtf8, fileName, true ) ) if ( !wl->parse ( rawBufferUtf8, fileName, true ) )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
wideError.Prepend ( _ ( "Cannot pretty-print: " ) ); wideError.Prepend ( _ ( "Cannot pretty-print: " ) );
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
messagePane ( wideError, CONST_WARNING ); messagePane ( wideError, CONST_WARNING );
@ -4323,8 +4318,7 @@ void MyFrame::OnEncoding ( wxCommandEvent& event )
res = wl->saveEncodingFromFile ( sourceFileName.name(), tempFileName.name(), selectionUtf8 ); res = wl->saveEncodingFromFile ( sourceFileName.name(), tempFileName.name(), selectionUtf8 );
if ( res == -1 ) if ( res == -1 )
{ {
std::string error = wl->getLastError(); wxString wideError = wl->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
wideError.Prepend ( _ ( "Cannot set encoding: " ) ); wideError.Prepend ( _ ( "Cannot set encoding: " ) );
messagePane ( wideError, CONST_STOP ); messagePane ( wideError, CONST_STOP );
return; return;
@ -4818,12 +4812,11 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml ); success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml );
if ( success ) if ( success )
{ {
std::string libxmlError = wl->getLastError(); wxString wideError = wl->getLastError();
bytes = utf8Buffer.size(); bytes = utf8Buffer.size();
wxString msg, wideEncoding, wideError; wxString msg, wideEncoding;
wideEncoding = wideEncoding =
wxString ( encoding.c_str(), wxConvUTF8, encoding.size() ); wxString ( encoding.c_str(), wxConvUTF8, encoding.size() );
wideError = wxString ( libxmlError.c_str(), wxConvUTF8, libxmlError.size() );
if ( wideError.empty() ) if ( wideError.empty() )
wideError = _ ( "unknown error" ); wideError = _ ( "unknown error" );