summaryrefslogtreecommitdiffstats
path: root/src/translators/csvimporter.cpp
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2014-03-03 13:46:44 +0100
committerSlávek Banko <slavek.banko@axis.cz>2014-03-03 13:46:44 +0100
commit2e02da046d3e56cdf4744f644af35ad07424f48b (patch)
treef2dcf353aa2338eae1c2ff2c41af971c580c2762 /src/translators/csvimporter.cpp
parent3c13229d98167ae4ae0710d5eeef23fef5005bf0 (diff)
downloadtellico-2e02da046d3e56cdf4744f644af35ad07424f48b.tar.gz
tellico-2e02da046d3e56cdf4744f644af35ad07424f48b.zip
Update to upstream version 1.3.6
Diffstat (limited to 'src/translators/csvimporter.cpp')
-rw-r--r--src/translators/csvimporter.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/translators/csvimporter.cpp b/src/translators/csvimporter.cpp
index 8a53ff9..d6198d0 100644
--- a/src/translators/csvimporter.cpp
+++ b/src/translators/csvimporter.cpp
@@ -50,15 +50,26 @@ extern "C" {
using Tellico::Import::CSVImporter;
+typedef int(*SpaceFunc)(char);
+
static void writeToken(char* buffer, size_t len, void* data);
static void writeRow(char buffer, void* data);
+static int isSpace(char c);
+static int isSpaceOrTab(char c);
+static int isTab(char c);
class CSVImporter::Parser {
public:
Parser(const TQString& str) : stream(new TQTextIStream(&str)) { csv_init(&parser, 0); }
~Parser() { csv_free(parser); delete stream; stream = 0; }
- void setDelimiter(const TQString& s) { Q_ASSERT(s.length() == 1); csv_set_delim(parser, s[0].latin1()); }
+ void setDelimiter(const TQString& s) {
+ Q_ASSERT(s.length() == 1);
+ csv_set_delim(parser, s[0].latin1());
+ if(s[0] == '\t') csv_set_space_func(parser, isSpace);
+ else if(s[0] == ' ') csv_set_space_func(parser, isTab);
+ else csv_set_space_func(parser, isSpaceOrTab);
+ }
void reset(const TQString& str) { delete stream; stream = new TQTextIStream(&str); };
bool hasNext() { return !stream->atEnd(); }
void skipLine() { stream->readLine(); }
@@ -95,6 +106,21 @@ static void writeRow(char c, void* data) {
p->setRowDone(true);
}
+static int isSpace(char c) {
+ if (c == CSV_SPACE) return 1;
+ return 0;
+}
+
+static int isSpaceOrTab(char c) {
+ if (c == CSV_SPACE || c == CSV_TAB) return 1;
+ return 0;
+}
+
+static int isTab(char c) {
+ if (c == CSV_TAB) return 1;
+ return 0;
+}
+
CSVImporter::CSVImporter(const KURL& url_) : Tellico::Import::TextImporter(url_),
m_coll(0),
m_existingCollection(0),