2010-04-01 11:15:48 +02:00
|
|
|
#include "csvfilereader.hh"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
using namespace boost ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
|
|
|
CSVFileReader::~CSVFileReader()
|
|
|
|
{
|
|
|
|
delete current_token ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note that this function is not called by the constructor, so you
|
|
|
|
* must manually call it prior to use read_field().
|
|
|
|
* @return false in case of error (EOF, etc.).
|
|
|
|
*/
|
|
|
|
bool CSVFileReader::next_line()
|
|
|
|
{
|
2010-06-22 09:34:17 +02:00
|
|
|
delete current_token ;
|
|
|
|
current_token = NULL ;
|
2010-04-01 11:15:48 +02:00
|
|
|
|
|
|
|
if (! read_nonblank_line(current_line))
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
// Split read string into fields (semicolon-separated)
|
|
|
|
current_token = new tokenizer<escaped_list_separator<char> >(
|
|
|
|
current_line, escaped_list_separator<char>('\\', separator, '\"')) ;
|
|
|
|
|
|
|
|
token_iterator = current_token->begin() ;
|
|
|
|
current_field_nb = 0 ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSVFileReader::print_error_cast()
|
|
|
|
{
|
|
|
|
cerr
|
|
|
|
<< "Bad value « "
|
|
|
|
<< *token_iterator << " » at line "
|
|
|
|
<< current_line_nb << ", field #"
|
|
|
|
<< current_field_nb << ", of input file « "
|
|
|
|
<< file_name << " »!" << endl ;
|
|
|
|
}
|