Kaydet (Commit) cdeb83ed authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in l10ntools

Change-Id: Ib8dafdb2b3831cdd9481fd19b340ac377c8dc9db
Reviewed-on: https://gerrit.libreoffice.org/62649
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst a3d5248b
...@@ -354,10 +354,10 @@ public: ...@@ -354,10 +354,10 @@ public:
SimpleXMLParser(); SimpleXMLParser();
~SimpleXMLParser(); ~SimpleXMLParser();
/// parse a file, returns NULL on critical errors /// parse a file, return false on critical errors
XMLFile *Execute( bool Execute(
const OString &rFileName, // the file name const OString &rFileName, // the file name
XMLFile *pXMLFileIn // the XMLFile XMLFile* pXMLFile // the XMLFile
); );
/// returns an error struct /// returns an error struct
......
...@@ -120,10 +120,11 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) ...@@ -120,10 +120,11 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
else else
{ {
HelpParser aParser( aArgs.m_sInputFile ); HelpParser aParser( aArgs.m_sInputFile );
std::unique_ptr<XMLFile> xmlfile(new XMLFile( OString('0') ));
hasNoError = hasNoError =
HelpParser::CreatePO( HelpParser::CreatePO(
aArgs.m_sOutputFile, aArgs.m_sInputFile, aArgs.m_sOutputFile, aArgs.m_sInputFile,
new XMLFile( OString('0') ), "help" ); xmlfile.get(), "help" );
} }
} }
catch (std::exception& e) catch (std::exception& e)
......
...@@ -81,13 +81,11 @@ HelpParser::HelpParser( const OString &rHelpFile ) ...@@ -81,13 +81,11 @@ HelpParser::HelpParser( const OString &rHelpFile )
bool HelpParser::CreatePO( bool HelpParser::CreatePO(
/*****************************************************************************/ /*****************************************************************************/
const OString &rPOFile_in, const OString &sHelpFile, const OString &rPOFile_in, const OString &sHelpFile,
XMLFile *pXmlFile, const OString &rGsi1){ XMLFile* pXmlFile, const OString &rGsi1){
SimpleXMLParser aParser; SimpleXMLParser aParser;
//TODO: explicit BOM handling? //TODO: explicit BOM handling?
std::unique_ptr <XMLFile> file ( aParser.Execute( sHelpFile, pXmlFile ) ); if (!aParser.Execute( sHelpFile, pXmlFile ))
if (file == nullptr)
{ {
printf( printf(
"%s: %s\n", "%s: %s\n",
...@@ -95,8 +93,8 @@ bool HelpParser::CreatePO( ...@@ -95,8 +93,8 @@ bool HelpParser::CreatePO(
aParser.GetError().m_sMessage.getStr()); aParser.GetError().m_sMessage.getStr());
exit(-1); exit(-1);
} }
file->Extract(); pXmlFile->Extract();
if( !file->CheckExportStatus() ){ if( !pXmlFile->CheckExportStatus() ){
return true; return true;
} }
...@@ -107,9 +105,9 @@ bool HelpParser::CreatePO( ...@@ -107,9 +105,9 @@ bool HelpParser::CreatePO(
return false; return false;
} }
XMLHashMap* aXMLStrHM = file->GetStrings(); XMLHashMap* aXMLStrHM = pXmlFile->GetStrings();
std::vector<OString> order = file->getOrder(); std::vector<OString> order = pXmlFile->getOrder();
for (auto const& pos : order) for (auto const& pos : order)
{ {
...@@ -150,8 +148,8 @@ bool HelpParser::Merge( const OString &rDestinationFile, ...@@ -150,8 +148,8 @@ bool HelpParser::Merge( const OString &rDestinationFile,
//TODO: explicit BOM handling? //TODO: explicit BOM handling?
std::unique_ptr<XMLFile> xmlfile(aParser.Execute( sHelpFile, new XMLFile( OString('0') ) )); std::unique_ptr<XMLFile> xmlfile(new XMLFile( OString('0') ));
if (!xmlfile) if (!aParser.Execute( sHelpFile, xmlfile.get()))
{ {
SAL_WARN("l10ntools", "could not parse " << sHelpFile); SAL_WARN("l10ntools", "could not parse " << sHelpFile);
return false; return false;
......
...@@ -869,7 +869,7 @@ void SimpleXMLParser::Default( const XML_Char *s, int len ) ...@@ -869,7 +869,7 @@ void SimpleXMLParser::Default( const XML_Char *s, int len )
new XMLDefault(OString( s, len ), m_pCurNode ); new XMLDefault(OString( s, len ), m_pCurNode );
} }
XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ) bool SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFile )
{ {
m_aErrorInformation.m_eCode = XML_ERROR_NONE; m_aErrorInformation.m_eCode = XML_ERROR_NONE;
m_aErrorInformation.m_nLine = 0; m_aErrorInformation.m_nLine = 0;
...@@ -883,7 +883,7 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -883,7 +883,7 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
if (osl_openFile(aFileURL.pData, &h, osl_File_OpenFlag_Read) if (osl_openFile(aFileURL.pData, &h, osl_File_OpenFlag_Read)
!= osl_File_E_None) != osl_File_E_None)
{ {
return nullptr; return false;
} }
sal_uInt64 s; sal_uInt64 s;
...@@ -896,10 +896,9 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -896,10 +896,9 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
if (e != osl_File_E_None) if (e != osl_File_E_None)
{ {
osl_closeFile(h); osl_closeFile(h);
return nullptr; return false;
} }
XMLFile* pXMLFile = pXMLFileIn;
pXMLFile->SetName( rFileName ); pXMLFile->SetName( rFileName );
m_pCurNode = pXMLFile; m_pCurNode = pXMLFile;
...@@ -915,7 +914,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -915,7 +914,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
else else
m_aErrorInformation.m_sMessage = "XML-File parsed successfully"; m_aErrorInformation.m_sMessage = "XML-File parsed successfully";
if (!XML_Parse(m_aParser, static_cast< char * >(p), s, true)) bool result = XML_Parse(m_aParser, static_cast< char * >(p), s, true);
if (!result)
{ {
m_aErrorInformation.m_eCode = XML_GetErrorCode( m_aParser ); m_aErrorInformation.m_eCode = XML_GetErrorCode( m_aParser );
m_aErrorInformation.m_nLine = XML_GetErrorLineNumber( m_aParser ); m_aErrorInformation.m_nLine = XML_GetErrorLineNumber( m_aParser );
...@@ -1004,14 +1004,12 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -1004,14 +1004,12 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
default: default:
break; break;
} }
delete pXMLFile;
pXMLFile = nullptr;
} }
osl_unmapMappedFile(h, p, s); osl_unmapMappedFile(h, p, s);
osl_closeFile(h); osl_closeFile(h);
return pXMLFile; return result;
} }
namespace namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment