From 801e7de1f85656746d832508baf4583907826420 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 23 Apr 2010 15:14:00 +0000 Subject: Minor updates to the List class, unchecked corner cases. The CsvWriter now writes csv. It understands both excel formatting and c-style, which I made up myself (it's just c-style escape sequences). Sha1 is converted to work with the CryptoHash API and it does indeed work. --- src/csvwriter.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/csvwriter.cpp') diff --git a/src/csvwriter.cpp b/src/csvwriter.cpp index 59a471f..3e2816b 100644 --- a/src/csvwriter.cpp +++ b/src/csvwriter.cpp @@ -34,13 +34,47 @@ Bu::CsvWriter::~CsvWriter() { } +void Bu::CsvWriter::writeLine( const StrArray &aStrs ) +{ + Bu::FString sBuf; + for( StrArray::const_iterator i = aStrs.begin(); i; i++ ) + { + if( i != aStrs.begin() ) + sBuf += ","; + sBuf += sEncode( *i ); + } + sBuf += "\n"; + + sOut.write( sBuf ); +} + Bu::FString Bu::CsvWriter::encodeExcel( const Bu::FString &sIn ) { - return ""; + if( sIn.find('\"') ) + { + Bu::FString sOut = "\""; + for( Bu::FString::const_iterator i = sIn.begin(); i; i++ ) + { + if( *i == '\"' ) + sOut += "\"\""; + else + sOut += *i; + } + return sOut; + } + return sIn; } Bu::FString Bu::CsvWriter::encodeC( const Bu::FString &sIn ) { - return ""; + Bu::FString sOut = ""; + for( Bu::FString::const_iterator i = sIn.begin(); i; i++ ) + { + if( *i == ',' ) + sOut += "\\,"; + else + sOut += *i; + } + return sOut; } -- cgit v1.2.3