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 )
{
std::string stdError = wrapLibxml.getLastError();
error = wxString ( stdError.c_str(), wxConvUTF8, stdError.size() );
error = wrapLibxml.getLastError();
return false;
}

View File

@ -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<int, int> WrapLibxml::getErrorPosition()

View File

@ -78,7 +78,7 @@ class WrapLibxml
const char *utf8DocBuf,
size_t utf8DocBufSize,
const wxString &docUrl );
std::string getLastError();
wxString getLastError();
std::pair<int, int> 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

View File

@ -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<int, int> 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" );