EgtGeneral 1.5f3 :

- Scan ora funziona anche con file di testo compressi (gzip).
This commit is contained in:
Dario Sassi
2014-06-18 07:28:33 +00:00
parent e696017fa8
commit 5e7774b78a
5 changed files with 28 additions and 8 deletions
+19 -8
View File
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : Scan.cpp Data : 17.04.14 Versione : 1.5d
// File : Scan.cpp Data : 17.06.14 Versione : 1.5f3
// Contenuto : Implementazione della classe Scanner.
// Scansione di file di testo con codifica UTF-8 (anche con BOM)
// e quindi anche ASCII.
@@ -10,6 +10,7 @@
// Modifiche : 30.09.13 DS Creazione modulo.
// 06.03.14 DS Aggiunta UngetLine.
// 17.04.14 DS Aggiunto parametro bSkipEmptyLine a Init.
// 17.06.14 DS Lettura di file compressi con formato gzip.
//
//----------------------------------------------------------------------------
@@ -18,16 +19,20 @@
#include "/EgtDEv/Include/EGnScan.h"
#include "/EgtDEv/Include/EGnStringUtils.h"
#include "/EgtDEv/Include/EGnStringConverter.h"
#include "/EgtDev/Extern/Zlib/Include/zlib.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Scanner::Init( const std::string& sFile, const char* szRemInit, bool bSkipEmptyLine)
{
// apertura del file di ingresso
m_InFile.open( stringtoW( sFile), ios::in) ;
m_InFile = gzopen_w( stringtoW( sFile), "rb") ;
if ( m_InFile != nullptr) {
const int DIM_BUFFER = 65536 ;
gzbuffer( m_InFile, DIM_BUFFER) ;
}
// reset vari
m_nLineNbr = 0 ;
@@ -47,15 +52,18 @@ Scanner::Init( const std::string& sFile, const char* szRemInit, bool bSkipEmptyL
// assegno flag per saltare linee vuote
m_bSkipEmptyLine = bSkipEmptyLine ;
return ( ! m_InFile.fail()) ;
return ( m_InFile != nullptr) ;
}
//----------------------------------------------------------------------------
bool
Scanner::Terminate( void)
{
if ( m_InFile.is_open())
m_InFile.close() ;
if ( m_InFile != nullptr) {
bool bOk = ( gzclose( m_InFile) == Z_OK) ;
m_InFile = nullptr ;
return bOk ;
}
return true ;
}
@@ -64,7 +72,7 @@ Scanner::Terminate( void)
bool
Scanner::GetLine( string& sLine)
{
if ( ! m_InFile.is_open())
if ( m_InFile == nullptr)
return false ;
if ( m_bUnget) {
@@ -74,12 +82,15 @@ Scanner::GetLine( string& sLine)
}
else {
int nOldLineNbr = m_nLineNbr ;
const int DIM_BUFF = 512 ;
char szBuffer[DIM_BUFF] ;
do {
if ( ! getline( m_InFile, sLine)) {
if ( gzgets( m_InFile, szBuffer, DIM_BUFF) == nullptr) {
sLine = "" ;
m_nDeltaLineUnget = m_nLineNbr - nOldLineNbr ;
return false ;
}
sLine = szBuffer ;
if ( m_nLineNbr == 0)
TrimUtf8Bom( sLine) ;
Trim( sLine) ;