2042d2b4ee
- aggiustate maiuscole/minuscole per inclusione file.
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : CmdScanner.cpp Data : 27.05.14 Versione : 1.5e2
|
|
// Contenuto : Implementazione della classe CmdScanner.
|
|
// Scansione di file di testo con codifica UTF-8 (anche con BOM)
|
|
// e quindi anche ASCII.
|
|
//
|
|
//
|
|
// Modifiche : 19.01.13 DS Creazione modulo.
|
|
// 27.05.14 DS Agg. gestione continuazione linea con carattere '\\' alla fine.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "CmdScanner.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EgtStringConverter.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
CmdScanner::CmdScanner( void)
|
|
{
|
|
m_nLineNbr = 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
CmdScanner::~CmdScanner( void)
|
|
{
|
|
Terminate() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CmdScanner::Init( const string& sCmdFile)
|
|
{
|
|
// se già aperto, lo chiudo
|
|
Terminate() ;
|
|
|
|
// apertura del file di ingresso
|
|
m_CmdFile.open( stringtoW( sCmdFile), ios::in) ;
|
|
|
|
// reset numero linea corrente
|
|
m_nLineNbr = 0 ;
|
|
|
|
// salvo path file
|
|
m_sFName = sCmdFile ;
|
|
|
|
return ( ! m_CmdFile.fail()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CmdScanner::Terminate( void)
|
|
{
|
|
if ( m_CmdFile.is_open())
|
|
m_CmdFile.close() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CmdScanner::GetLine( string& sLine)
|
|
{
|
|
if ( ! m_CmdFile.is_open())
|
|
return false ;
|
|
// leggu una linea
|
|
if ( ! GetSingleLine( sLine))
|
|
return false ;
|
|
// mentre alla fine c'è il carattere di continuazione, leggo la successiva
|
|
string sCont ;
|
|
while ( ! sLine.empty() && sLine.back() == '\\') {
|
|
// elimino il carattere di continuazione linea
|
|
sLine.pop_back() ;
|
|
// leggo la linea successiva
|
|
if ( GetSingleLine( sCont))
|
|
sLine += sCont ;
|
|
else
|
|
break ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CmdScanner::GetSingleLine( string& sLine)
|
|
{
|
|
do {
|
|
if ( ! getline( m_CmdFile, sLine))
|
|
return false ;
|
|
if ( m_nLineNbr == 0)
|
|
TrimUtf8Bom( sLine) ;
|
|
TrimLeft( sLine) ;
|
|
m_nLineNbr ++ ;
|
|
} while ( sLine.empty() || sLine.find( "//") == 0) ;
|
|
|
|
return true ;
|
|
}
|