From 469bbcf0701e1eb8a6670c23145b0da87357e178 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 25 Mar 2012 20:00:08 +0000 Subject: Code is all reorganized. We're about ready to release. I should write up a little explenation of the arrangement. --- src/stable/csvreader.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/stable/csvreader.cpp (limited to 'src/stable/csvreader.cpp') diff --git a/src/stable/csvreader.cpp b/src/stable/csvreader.cpp new file mode 100644 index 0000000..4da7883 --- /dev/null +++ b/src/stable/csvreader.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2007-2011 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/csvreader.h" +#include "bu/stream.h" + +#include "bu/sio.h" +using namespace Bu; + +Bu::CsvReader::CsvReader( Bu::Stream &sIn, Bu::CsvReader::Style eStyle ) : + sIn( sIn ) +{ + switch( eStyle ) + { + case styleExcel: + sDecode = Bu::slot( &decodeExcel ); + break; + + case styleC: + sDecode = Bu::slot( &decodeC ); + break; + } +} + +Bu::CsvReader::CsvReader( Bu::Stream &sIn, + Bu::CsvReader::DecodeSignal sDecode ) : + sIn( sIn ), + sDecode( sDecode ) +{ +} + +Bu::CsvReader::~CsvReader() +{ +} + +Bu::StrArray Bu::CsvReader::readLine() +{ + Bu::StrArray aVals; + + Bu::String sLine = sIn.readLine(); + + if( !sLine.isSet() ) + return Bu::StrArray(); + + Bu::String::iterator i = sLine.begin(); + + aVals.append( sDecode( i ) ); + + while( i ) + { + if( *i == ',' ) + { + i++; + if( !i ) + { + aVals.append(""); + break; + } + aVals.append( sDecode( i ) ); + } + else + { + // Blanks and stuff? + sio << "Out of bound: '" << *i << "'" << sio.nl; + i++; + } + } + + return aVals; +} + +Bu::String Bu::CsvReader::decodeExcel( Bu::String::iterator &i ) +{ + Bu::String sRet; + + for(; i && (*i == ' ' || *i == '\t'); i++ ) { } + + if( !i ) + return sRet; + + if( *i == '\"' ) + { + for( i++ ; i; i++ ) + { + if( *i == '\"' ) + { + i++; + if( !i ) + { + return sRet; + } + else if( *i == '\"' ) + { + sRet += *i; + } + else + { + return sRet; + } + } + else + { + sRet += *i; + } + } + } + else + { + for( ; i; i++ ) + { + if( *i == ',' ) + { + return sRet; + } + sRet += *i; + } + } + + return sRet; +} + +Bu::String Bu::CsvReader::decodeC( Bu::String::iterator & ) +{ + return ""; +} + -- cgit v1.2.3