22 #ifndef CSVDATALOADER_H_
23 #define CSVDATALOADER_H_
24 #include <tulip/tulipconf.h>
29 #include <QtCore/QTextCodec>
30 #include <QtCore/QString>
31 #include "tulip/CSVContentHandler.h"
42 class TLP_QT_SCOPE CSVParser {
44 virtual ~CSVParser() {}
66 class TLP_QT_SCOPE CSVSimpleParser :
public CSVParser {
76 CSVSimpleParser(
const std::string& fileName,
const std::string& separator=std::string(
";"),
char textDelimiter=
'"',
const std::string& fileEncoding=std::string(
"UTF-8"),
unsigned int firstLine = 0,
unsigned int lastLine = UINT_MAX);
78 virtual ~CSVSimpleParser();
80 std::string fileName()
const {
83 void setFileName(
const std::string& fileName) {
86 std::string separator()
const {
90 void setSeparator(
const std::string& separator) {
91 _separator = separator;
94 char textDelimiter()
const {
95 return _textDelimiter;
98 void setTextDelimiter(
char delimiter) {
99 _textDelimiter = delimiter;
102 std::string fileEncoding()
const {
103 return _fileEncoding;
106 void setFileEncoding(
const std::string& fileEncoding) {
107 _fileEncoding = fileEncoding;
113 virtual std::string treatToken(
const std::string& token,
int row,
int column);
116 void tokenize(
const std::string& str, std::vector<std::string>& tokens,
117 const std::string& delimiters,
char _textDelimiter,
unsigned int numberOfCol);
118 inline std::string convertStringEncoding(
const std::string& toConvert,QTextCodec* encoder) {
119 return std::string(encoder->toUnicode ( toConvert.c_str() ).toUtf8().data());
125 bool multiplatformgetline ( std::istream& is, std::string& str );
127 std::string removeQuotesIfAny(
const std::string &s,
const std::string& rejectedChars);
128 std::string _fileName;
129 std::string _separator;
131 std::string _fileEncoding;
132 unsigned int _firstLine;
133 unsigned int _lastLine;
140 class TLP_QT_SCOPE CSVInvertMatrixParser :
public tlp::CSVParser ,
public tlp::CSVContentHandler {
142 CSVInvertMatrixParser(CSVParser* parser);
143 virtual ~CSVInvertMatrixParser();
148 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
149 void end(
unsigned int rowNumber,
unsigned int columnNumber);
152 CSVContentHandler *handler;
153 std::vector<std::vector<std::string> > columns;
154 unsigned int maxLineSize;