Files
EgtGeneral/Scan.cpp
T
Dario Sassi d8f3704d20 EgtGeneral 1.5d4 :
- aggiunto param. bSkipEmptyLine a Init di Scanner
- aggiunto a TSC comando EXEC con sottocomandi SKIP, DO e STOP.
2014-04-21 21:53:35 +00:00

104 lines
2.9 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : Scan.cpp Data : 17.04.14 Versione : 1.5d
// Contenuto : Implementazione della classe Scanner.
// Scansione di file di testo con codifica UTF-8 (anche con BOM)
// e quindi anche ASCII.
//
//
// Modifiche : 30.09.13 DS Creazione modulo.
// 06.03.14 DS Aggiunta UngetLine.
// 17.04.14 DS Aggiunto parametro bSkipEmptyLine a Init.
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "/EgtDEv/Include/EGnScan.h"
#include "/EgtDEv/Include/EGnStringUtils.h"
#include "/EgtDEv/Include/EGnStringConverter.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) ;
// reset vari
m_nLineNbr = 0 ;
m_bUnget = false ;
m_nDeltaLineUnget = 0 ;
// salvo path file
m_sFName = sFile ;
// assegno i caratteri di inizio commento
if ( szRemInit != NULL)
m_sRemInit = szRemInit ;
else
m_sRemInit = "//" ;
// assegno flag per saltare linee vuote
m_bSkipEmptyLine = bSkipEmptyLine ;
return ( ! m_InFile.fail()) ;
}
//----------------------------------------------------------------------------
bool
Scanner::Terminate( void)
{
if ( m_InFile.is_open())
m_InFile.close() ;
return true ;
}
//----------------------------------------------------------------------------
bool
Scanner::GetLine( string& sLine)
{
if ( ! m_InFile.is_open())
return false ;
if ( m_bUnget) {
sLine = m_sUnget ;
m_bUnget = false ;
m_nLineNbr += m_nDeltaLineUnget ;
}
else {
int nOldLineNbr = m_nLineNbr ;
do {
if ( ! getline( m_InFile, sLine)) {
sLine = "" ;
m_nDeltaLineUnget = m_nLineNbr - nOldLineNbr ;
return false ;
}
if ( m_nLineNbr == 0)
TrimUtf8Bom( sLine) ;
Trim( sLine) ;
m_nLineNbr ++ ;
} while ( ( m_bSkipEmptyLine && sLine.empty()) || sLine.find( m_sRemInit) == 0) ;
m_nDeltaLineUnget = m_nLineNbr - nOldLineNbr ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
Scanner::UngetLine( string& sLine)
{
if ( m_bUnget)
return false ;
m_sUnget = sLine ;
m_bUnget = true ;
m_nLineNbr -= m_nDeltaLineUnget ;
return true ;
}