summaryrefslogtreecommitdiff
path: root/src/csvreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/csvreader.cpp')
-rw-r--r--src/csvreader.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/csvreader.cpp b/src/csvreader.cpp
new file mode 100644
index 0000000..a28c2c3
--- /dev/null
+++ b/src/csvreader.cpp
@@ -0,0 +1,100 @@
1#include "bu/csvreader.h"
2#include "bu/stream.h"
3
4#include "bu/sio.h"
5using namespace Bu;
6
7Bu::CsvReader::CsvReader( Bu::Stream &sIn, Bu::CsvReader::Style eStyle ) :
8 sIn( sIn )
9{
10 switch( eStyle )
11 {
12 case styleExcel:
13 sDecode = Bu::slot( &decodeExcel );
14 break;
15
16 case styleC:
17 sDecode = Bu::slot( &decodeExcel );
18 break;
19 }
20}
21
22Bu::CsvReader::CsvReader( Bu::Stream &sIn,
23 Bu::CsvReader::DecodeSignal sDecode ) :
24 sIn( sIn ),
25 sDecode( sDecode )
26{
27}
28
29Bu::CsvReader::~CsvReader()
30{
31}
32
33Bu::StrArray Bu::CsvReader::readLine()
34{
35 Bu::StrArray aVals;
36
37 Bu::FString sLine = sIn.readLine();
38
39 for( Bu::FString::iterator i = sLine.begin(); i; i++ )
40 {
41 if( *i == ',' )
42 {
43 }
44 else
45 {
46 aVals.append( sDecode( i ) );
47 }
48 }
49
50 return aVals;
51}
52
53Bu::FString Bu::CsvReader::decodeExcel( Bu::FString::iterator &i )
54{
55 Bu::FString sRet;
56
57 for(; i && (*i == ' ' || *i == '\t'); i++ ) { }
58
59 if( *i == '\"' )
60 {
61 for( i++ ; i; i++ )
62 {
63 if( *i == '\"' )
64 {
65 i++;
66 if( *i == '\"' )
67 {
68 sRet += *i;
69 }
70 else
71 {
72 return sRet;
73 }
74 }
75 else
76 {
77 sRet += *i;
78 }
79 }
80 }
81 else
82 {
83 for( ; i; i++ )
84 {
85 if( *i == ',' )
86 {
87 return sRet;
88 }
89 sRet += *i;
90 }
91 }
92
93 return sRet;
94}
95
96Bu::FString Bu::CsvReader::decodeC( Bu::FString::iterator &i )
97{
98 return "";
99}
100