Skip to content

Commit 8186bc5

Browse files
author
israel.ekpo
committed
M trunk/AUTHORS
M trunk/ChangeLog M trunk/README M trunk/NEWS Added more documentation to the readme file
1 parent 9564fb5 commit 8186bc5

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

AUTHORS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Israel Ekpo <[email protected]>
3+
4+

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
No changes has been made yet since the first release
3+
4+

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Version 1.0 has been released.
3+
4+

README

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
===========================================================
3+
Introduction
4+
===========================================================
5+
6+
The home page for this project is : http://code.google.com/p/csv-parser-cplusplus/
7+
8+
This is a C++ library for parsing text files.
9+
10+
The records could be comma delimited, tab delimited or delimited with any set of characters.
11+
12+
The csv_parser class is used to parse text files to extract records and fields.
13+
14+
We are making the following assumptions :
15+
16+
* The record terminator is only one character in length.
17+
* The field terminator is only one character in length.
18+
* The fields are enclosed by single characters, if any.
19+
20+
* The parser can handle documents where fields are always enclosed, not enclosed at all or optionally enclosed.
21+
* When fields are strictly all enclosed, there is an assumption that any enclosure characters within the field are escaped by placing a backslash in front of the enclosure character.
22+
23+
The CSV files can be parsed in 3 modes.
24+
25+
* (a) No enclosures
26+
* (b) Fields always enclosed.
27+
* (c) Fields optionally enclosed.
28+
29+
For option (c) when the enclosure character is optional, if an enclosure character is spotted at either the beginning or the end of the string, it is assumed that the field is enclosed.
30+
31+
The csv_parser::init() method can accept a character array as the path to the CSV file. Since it is overloaded, it can also accept a FILE pointer to a stream that is already open for reading.
32+
33+
The set_enclosed_char() method accepts the field enclosure character as the first parameter and the enclosure mode as the second parameter which controls how the text file is going to be parsed.
34+
35+
More documentation of the souce is available in the doc folder
36+
37+
============================================================
38+
LIBRARY INSTALLATION
39+
============================================================
40+
41+
Decompress the tarball
42+
43+
tar -zxvf csv_parser-x.x.tar.gz
44+
45+
cd csv_parser
46+
47+
Configure, compile and install
48+
49+
./configure
50+
51+
make
52+
53+
make all install
54+
55+
==============================================================
56+
COMPILING SOURCE PROGRAMS AND LINKING TO THE LIBRARY
57+
==============================================================
58+
g++ -Wall -O2 -g `csv_parser-config --cxxflags --libs` example.cpp -o example
59+
60+
==============================================================
61+
EXAMPLE USAGE :
62+
==============================================================
63+
64+
#include <csv_parser/csv_parser.hpp>
65+
66+
int main(void)
67+
{
68+
const char * filename = "example_input.csv";
69+
const char field_terminator = ',';
70+
const char line_terminator = '\n';
71+
const char enclosure_char = '"';
72+
73+
csv_parser file_parser;
74+
75+
file_parser.set_skip_lines(1);
76+
77+
file_parser.init(filename);
78+
file_parser.set_enclosed_char(enclosure_char, ENCLOSURE_OPTIONAL);
79+
file_parser.set_field_term_char(field_terminator);
80+
file_parser.set_line_term_char(line_terminator);
81+
82+
unsigned int row_count = 1U;
83+
84+
while(file_parser.has_more_rows())
85+
{
86+
unsigned int i = 0;
87+
88+
csv_row row = file_parser.get_row();
89+
90+
for (i = 0; i < row.size(); i++)
91+
{
92+
printf("COLUMN %02d : %s\n", i + 1U, row[i].c_str());
93+
}
94+
95+
printf("====================================================================\n");
96+
printf("END OF ROW %02d\n", row_count);
97+
printf("====================================================================\n");
98+
99+
row_count++;
100+
}
101+
102+
return 0;
103+
}
104+
105+
106+

0 commit comments

Comments
 (0)