aboutsummaryrefslogtreecommitdiff
path: root/src/stable/csvwriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/csvwriter.cpp')
-rw-r--r--src/stable/csvwriter.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/src/stable/csvwriter.cpp b/src/stable/csvwriter.cpp
index a89b309..8b51115 100644
--- a/src/stable/csvwriter.cpp
+++ b/src/stable/csvwriter.cpp
@@ -9,24 +9,24 @@
9#include "bu/stream.h" 9#include "bu/stream.h"
10 10
11Bu::CsvWriter::CsvWriter( Bu::Stream &sOut, Bu::CsvWriter::Style eStyle ) : 11Bu::CsvWriter::CsvWriter( Bu::Stream &sOut, Bu::CsvWriter::Style eStyle ) :
12 sOut( sOut ) 12 sOut( sOut )
13{ 13{
14 switch( eStyle ) 14 switch( eStyle )
15 { 15 {
16 case styleExcel: 16 case styleExcel:
17 sEncode = Bu::slot( &encodeExcel ); 17 sEncode = Bu::slot( &encodeExcel );
18 break; 18 break;
19 19
20 case styleC: 20 case styleC:
21 sEncode = Bu::slot( &encodeExcel ); 21 sEncode = Bu::slot( &encodeExcel );
22 break; 22 break;
23 } 23 }
24} 24}
25 25
26Bu::CsvWriter::CsvWriter( Bu::Stream &sOut, 26Bu::CsvWriter::CsvWriter( Bu::Stream &sOut,
27 Bu::CsvWriter::EncodeSignal sEncode ) : 27 Bu::CsvWriter::EncodeSignal sEncode ) :
28 sOut( sOut ), 28 sOut( sOut ),
29 sEncode( sEncode ) 29 sEncode( sEncode )
30{ 30{
31} 31}
32 32
@@ -36,46 +36,46 @@ Bu::CsvWriter::~CsvWriter()
36 36
37void Bu::CsvWriter::writeLine( const StrArray &aStrs ) 37void Bu::CsvWriter::writeLine( const StrArray &aStrs )
38{ 38{
39 Bu::String sBuf; 39 Bu::String sBuf;
40 for( StrArray::const_iterator i = aStrs.begin(); i; i++ ) 40 for( StrArray::const_iterator i = aStrs.begin(); i; i++ )
41 { 41 {
42 if( i != aStrs.begin() ) 42 if( i != aStrs.begin() )
43 sBuf += ","; 43 sBuf += ",";
44 sBuf += sEncode( *i ); 44 sBuf += sEncode( *i );
45 } 45 }
46 sBuf += "\n"; 46 sBuf += "\n";
47 47
48 sOut.write( sBuf ); 48 sOut.write( sBuf );
49} 49}
50 50
51Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn ) 51Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn )
52{ 52{
53 if( sIn.find('\"') || sIn.find(',') ) 53 if( sIn.find('\"') || sIn.find(',') )
54 { 54 {
55 Bu::String sOut = "\""; 55 Bu::String sOut = "\"";
56 for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) 56 for( Bu::String::const_iterator i = sIn.begin(); i; i++ )
57 { 57 {
58 if( *i == '\"' ) 58 if( *i == '\"' )
59 sOut += "\"\""; 59 sOut += "\"\"";
60 else 60 else
61 sOut += *i; 61 sOut += *i;
62 } 62 }
63 sOut += '\"'; 63 sOut += '\"';
64 return sOut; 64 return sOut;
65 } 65 }
66 return sIn; 66 return sIn;
67} 67}
68 68
69Bu::String Bu::CsvWriter::encodeC( const Bu::String &sIn ) 69Bu::String Bu::CsvWriter::encodeC( const Bu::String &sIn )
70{ 70{
71 Bu::String sOut = ""; 71 Bu::String sOut = "";
72 for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) 72 for( Bu::String::const_iterator i = sIn.begin(); i; i++ )
73 { 73 {
74 if( *i == ',' ) 74 if( *i == ',' )
75 sOut += "\\,"; 75 sOut += "\\,";
76 else 76 else
77 sOut += *i; 77 sOut += *i;
78 } 78 }
79 return sOut; 79 return sOut;
80} 80}
81 81