https://github.com/devwurm/csv-library
A simple stream or object based csv parsing and creating library for C++.
https://github.com/devwurm/csv-library
Last synced: 3 months ago
JSON representation
A simple stream or object based csv parsing and creating library for C++.
- Host: GitHub
- URL: https://github.com/devwurm/csv-library
- Owner: DevWurm
- Created: 2015-04-05T08:04:06.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-22T08:34:21.000Z (almost 11 years ago)
- Last Synced: 2024-12-31T06:13:59.841Z (over 1 year ago)
- Language: C++
- Size: 156 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: license/gpl-3.0.txt
Awesome Lists containing this project
README
# csv_library
A simple stream or object based csv parsing and creating library for C++.
With the library you can stream an CSV File into an object or you add
a CSV line as string into the object and get a deque object with the parsed data.
The data can get streamed out of the object or yout get a copy of the data from a member function.
The same way you can stream or add a deque with data into an object and get a CSV string.
##Library
Because the code is based on templates, the library is directory with C++ header files, that is generated by
make. Copy the directory into your project and include the libcsv.h file into your project files.
##How to use
#include "./libcsv/libcsv.h" //include the header
#include
#include
#include
#include
int main() {
csv::csv_handlerhandler; //create a handler object for int
//(from namespace csv)
std::ifstream input("file.csv"); //open input file
std::ofstream output("file2.csv"); //open output file
std::deque data; //deque object to store data (is used like vector)
std::string buffer;
//stream version
input >> handler >> data; //read one line from input and store
//parsed data in data
data >> handler >> output; //write the data from data into on one
//line of output
//possible [but not very useful]: stream one line from input through data
//into output and add a newline
input >> handler >> data >> handler >> output << std::endl;
//member function version
getline(input, buffer); //read one line from input into buffer
handler.set_csv_line(buffer); //put CSV string into handler (and parse)
data = handler.get_parsed_line(); //get parsed data and store in data
handler.set_parsed_line(data); //put parsed data into handler
//(and create CSV string)
buffer = handler.get_csv_line(); //get CSV String and store into buffer
output << buffer; //write buffer into file
return 0;
}
You can use the CSV Handler object as an 'tunnel' between a stream and a variable or another stream, or you can set
and get data in and from the Handler over public member functions. You can also mix those two ways (conversion is always
done at setting data/streaming data into object).
You can also use seperate objects for input/conversion do deque and output/conversion to string (here use ::set_line(DATA)
and DATA ::getline():
csv::csv_parser parser;
input >> parser >> data;
getline(input, buffer);
parser.set_line(buffer);
data = parser.get_line();
csv::csv_creator creator;
data >> creator >> output;
parser.set_line(data);
buffer = parser.get_line();
output << buffer;
The data stored in the csv object are deleted from there after get()ting them or streaming them out of the object.
The csv objects work with all instances and derivations of ostream and istream.
##License
Copyright 2015 DevWurm
'csv_library' is offered under GPL 3 License (Read ./license/gpl-3.0.txt)
##Documentation
Documentation will be offered soon. (Email me if you have any questions)
##Setup
Building:
To build the library file change into the top directory of the project and use make
with
make
on linux or
mingw32-make
,
on windows (only if mingw is installed).
Using:
Include the libcsv.h header file into your source file(s)
#include "libcsv.h"
Then you can use the objects and their members.
All the Element functions are showed in the how to use section.
##Authors
DevWurm
Email: devwurm@gmx.net
Feel free to contact me, if you have any questions or ideas about the project :)
##Collaborating
You can use the GitHub issue tracker for bugs and feature requests or create a pull request to submit
changes and forks are welcome, too.
If you don't want to use these possibilities, you can also write me an email at
devwurm@gmx.net.