88 lines
2.2 KiB
C++
88 lines
2.2 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalS
|
|
//----------------------------------------------------------------------------
|
|
// File : Scan.cpp Data : 30.09.13 Versione : 1.2a1
|
|
// Contenuto : Implementazione della classe CCmdScan.
|
|
// Scansione di file di testo con codifica UTF-8 (anche con BOM)
|
|
// e quindi anche ASCII.
|
|
//
|
|
//
|
|
// Modifiche : 30.09.13 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "/EgtDEv/Include/EGnScan.h"
|
|
#include "/EgtDEv/Include/EGnStringUtils.h"
|
|
#include "/EgtDEv/Include/EGnStringConverter.h"
|
|
|
|
using namespace std ;
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
Scanner::Scanner( void)
|
|
{
|
|
m_nLineNbr = 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Scanner::~Scanner( void)
|
|
{
|
|
Terminate() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Scanner::Init( const std::string& sFile, const char* szRemInit)
|
|
{
|
|
// apertura del file di ingresso
|
|
m_InFile.open( stringtoW( sFile), ios::in) ;
|
|
|
|
// reset numero linea corrente
|
|
m_nLineNbr = 0 ;
|
|
|
|
// salvo path file
|
|
m_sFName = sFile ;
|
|
|
|
// assegno i caratteri di inizio commento
|
|
if ( szRemInit != NULL)
|
|
m_sRemInit = szRemInit ;
|
|
else
|
|
m_sRemInit = "//" ;
|
|
|
|
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 ;
|
|
|
|
do {
|
|
if ( ! getline( m_InFile, sLine)) {
|
|
sLine = "" ;
|
|
return false ;
|
|
}
|
|
if ( m_nLineNbr == 0)
|
|
TrimUtf8Bom( sLine) ;
|
|
Trim( sLine) ;
|
|
m_nLineNbr ++ ;
|
|
} while ( sLine.empty() || sLine.find( m_sRemInit) == 0) ;
|
|
|
|
return true ;
|
|
}
|