From 80229a3686bbc451085ebc8b2432e4814378b4ac Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sun, 15 Dec 2013 22:21:31 +0800 Subject: [PATCH] Replaced std::string with wxString --- src/wrapdaisy.cpp | 3 +-- src/wraplibxml.cpp | 26 ++++++++++---------------- src/wraplibxml.h | 6 +++--- src/xmlcopyeditor.cpp | 23 ++++++++--------------- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/wrapdaisy.cpp b/src/wrapdaisy.cpp index 23b71ef..6d45599 100644 --- a/src/wrapdaisy.cpp +++ b/src/wrapdaisy.cpp @@ -128,8 +128,7 @@ bool WrapDaisy::run ( if ( !success ) { - std::string stdError = wrapLibxml.getLastError(); - error = wxString ( stdError.c_str(), wxConvUTF8, stdError.size() ); + error = wrapLibxml.getLastError(); return false; } diff --git a/src/wraplibxml.cpp b/src/wraplibxml.cpp index 1a04ea3..49055c4 100644 --- a/src/wraplibxml.cpp +++ b/src/wraplibxml.cpp @@ -103,7 +103,6 @@ void WrapLibxml::Init ( const wxString &catalogPath ) throw() WrapLibxml::WrapLibxml ( bool netAccessParameter ) : netAccess ( netAccessParameter ) - , errorLine ( 0 ) { WrapLibxml::Init(); } @@ -500,8 +499,8 @@ bool WrapLibxml::xslt ( } while ( false ); xmlFreeDoc ( doc ); - xmlFreeDoc ( res ); xmlFreeParserCtxt ( ctxt ); + xmlFreeDoc ( res ); xsltFreeStylesheet ( cur ); return ret; @@ -592,33 +591,28 @@ int WrapLibxml::saveEncodingFromFile ( // ensure entity warnings are treated as errors! if ( !getLastError().empty() ) - return -1; + result = -1; xmlFreeDoc ( docPtr ); xmlFreeParserCtxt ( ctxt ); + return result; } -std::string WrapLibxml::getLastError() +wxString WrapLibxml::getLastError() { xmlErrorPtr err = xmlGetLastError(); if ( !err ) - { return nonParserError; - } - std::stringstream ss; - ss << "Error at line "; - ss << err->line; + wxString error ( err->message, wxConvLocal ); if ( err->int2 ) - { - ss << ", column "; - ss << err->int2; - } - ss << ": "; - ss << err->message; - return ss.str(); + return wxString::Format ( _("Error at line %d, column %d: %s"), + err->line, err->int2, error.c_str() ); + + return wxString::Format ( _("Error at line %d: %s"), + err->line, error.c_str() ); } std::pair WrapLibxml::getErrorPosition() diff --git a/src/wraplibxml.h b/src/wraplibxml.h index f6d02b9..cb48993 100644 --- a/src/wraplibxml.h +++ b/src/wraplibxml.h @@ -78,7 +78,7 @@ class WrapLibxml const char *utf8DocBuf, size_t utf8DocBufSize, const wxString &docUrl ); - std::string getLastError(); + wxString getLastError(); std::pair getErrorPosition(); std::string getOutput(); int saveEncoding ( @@ -94,8 +94,8 @@ class WrapLibxml const wxString &systemId ); private: bool netAccess; - std::string output, nonParserError; - int errorLine; + std::string output; + wxString nonParserError; }; #endif diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 1fd19a6..f0e1975 100644 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -3781,8 +3781,7 @@ void MyFrame::OnValidateDTD ( wxCommandEvent& event ) wxString fname = doc->getFullFileName(); if ( !wl->validate ( doc->myGetTextRaw(), fname ) ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); statusProgress ( wxEmptyString ); messagePane ( wideError, CONST_WARNING ); @@ -3858,8 +3857,7 @@ void MyFrame::validateRelaxNG ( if ( !wl->validateRelaxNG ( schemaName, doc->myGetTextRaw(), fileName ) ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); statusProgress ( wxEmptyString ); std::pair posPair = wl->getErrorPosition(); @@ -4060,8 +4058,7 @@ void MyFrame::OnXPath ( wxCommandEvent& event ) if ( !success ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); if ( !wideError.empty() ) wideError.Prepend ( _T ( ": " ) ); wideError.Prepend ( _ ( "Cannot evaluate XPath" ) ); @@ -4189,8 +4186,7 @@ void MyFrame::OnXslt ( wxCommandEvent& event ) wxString fileName = doc->getFullFileName(); if ( !wl->xslt ( path, rawBufferUtf8, fileName ) ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); wideError.Prepend ( _ ( "Cannot transform: " ) ); statusProgress ( wxEmptyString ); messagePane ( wideError, CONST_WARNING ); @@ -4238,8 +4234,7 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event ) if ( !wl->parse ( rawBufferUtf8, fileName, true ) ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); wideError.Prepend ( _ ( "Cannot pretty-print: " ) ); statusProgress ( wxEmptyString ); messagePane ( wideError, CONST_WARNING ); @@ -4323,8 +4318,7 @@ void MyFrame::OnEncoding ( wxCommandEvent& event ) res = wl->saveEncodingFromFile ( sourceFileName.name(), tempFileName.name(), selectionUtf8 ); if ( res == -1 ) { - std::string error = wl->getLastError(); - wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); + wxString wideError = wl->getLastError(); wideError.Prepend ( _ ( "Cannot set encoding: " ) ); messagePane ( wideError, CONST_STOP ); return; @@ -4818,12 +4812,11 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified success = saveRawUtf8 ( fileNameLocal, utf8Buffer, false, isXml ); if ( success ) { - std::string libxmlError = wl->getLastError(); + wxString wideError = wl->getLastError(); bytes = utf8Buffer.size(); - wxString msg, wideEncoding, wideError; + wxString msg, wideEncoding; wideEncoding = wxString ( encoding.c_str(), wxConvUTF8, encoding.size() ); - wideError = wxString ( libxmlError.c_str(), wxConvUTF8, libxmlError.size() ); if ( wideError.empty() ) wideError = _ ( "unknown error" );