csvpp

csvpp Commit Details


Date:2014-03-25 22:32:00 (10 years 8 months ago)
Author:Natalie Adams
Branch:default
Commit:7518b6265aa0
Parents: 6bb7abecbe5c
Message:Changing delimiter to string because of split function

Changes:
Minclude/csvpp.h (1 diff)
Msrc/csvpp.cpp (4 diffs)

File differences

include/csvpp.h
1818
1919
2020
21
21
2222
2323
2424
2525
2626
27
27
2828
2929
3030
private:
std::vector<std::string> header;
bool skipheader;
char delimiter_char;
std::string delimiter_char; // this is a string because the split function helper is expecting a string, but really this is just a char
public:
const char * newline;
// Adding support for custom delimiter character
// Based on the patch by Hanifa
// https://code.google.com/p/csvpp/issues/detail?id=2
RowReader(char delimiter_char = ',', bool skipheader=false,const char * newline="\n") : skipheader(skipheader), newline(newline) { }
RowReader(std::string delimiter_char = ',', bool skipheader=false,const char * newline="\n") : skipheader(skipheader), newline(newline) { }
void clear() { header.clear(); }
friend std::istream & operator>>(std::istream & os, RowReader & r);
friend std::ostream & operator<<(std::ostream & os, const RowWriter & r);
src/csvpp.cpp
1414
1515
1616
17
1718
1819
1920
......
2223
2324
2425
25
26
2627
2728
2829
......
3132
3233
3334
34
35
3536
3637
3738
......
7374
7475
7576
76
77
7778
7879
7980
std::ostream & operator<<(std::ostream & os, const RowWriter & r)
{
rowiterator it;
if (r.size() == 0)
return os;
{
for(unsigned int i = 0; i < r[0].header.size() - 1; i++)
{
os << r[0].header[i] << this->delimiter_char;
os << r[0].header[i] << r[0].delimiter_char;;
}
os << r[0].header[r[0].header.size() - 1] << r[0].newline;
}
for(it = r[i].begin(); it != r[i].end(); it++)
{
if (distance(r[i].begin(), it) != (int)(r[i].size() - 1))
os << it->second << this->delimiter_char;
os << it->second << r[i].delimiter_char;
else
os << it->second;
}
If we aren't inside of a quote - store the value using the current header 'pointer' and keep scanning
*/
if (c == r.delimiter_char)
if (c == r.delimiter_char[0])
{
if (startquote)
{

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.40401s using 14 queries.