- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtst_csv.cpp
More file actions
Latest commit
68 lines (57 loc) · 1.25 KB
/
Copy pathtst_csv.cpp
File metadata and controls
68 lines (57 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include<assert.h>
#include"csvparser.h"
#include"csvwriter.h"
#include"simplecsv.h"
#if !defined(__GXX_EXPERIMENTAL_CXX0X__)&&(__cplusplus<201103L)
#defineoverride
#endif
classdebug_builder : publiccsv_builder {
public:
voidbegin_row() override {
printf("begin_row\n");
}
voidcell(constchar *buf,int len) override {
if (!buf) {
printf("(null) ");
} else {
printf("\"%.*s\"",len,buf);
}
}
voidend_row() override {
printf("end_row\n");
}
};
classnull_builder : publiccsv_builder {
public:
voidcell(constchar *buf,int len) override {}
};
structfile_out {
file_out(FILE *f) : f(f) { assert(f); }
voidoperator()(constchar *buf,int len) {
fwrite(buf,1,len,f);
}
private:
FILE *f;
};
intmain(int argc,char **argv)
{
// debug_builder dbg;
// null_builder dbg;
// csv_writer<file_out> dbg((file_out(stdout))); // CPP11: dbg{{stdout}}
// csv_writer<file_out> dbg(file_out(stdout),'\'',',',true);
#if1
SimpleCSV::Table tbl;
SimpleCSV::builder dbg(tbl);
#endif
csvparser cp(dbg,'\'');
cp(
"\n"
"1, 's' , 3,4 a\n"
",1,2,3,4\n"
" asdf, 'asd''df', s\n"
);
csv_writer<file_out> dbg2(file_out(stdout),'\'',',',true);
tbl.write(dbg2);
return0;
}