[Kst] kdeextragear-2/kst/kst/datasources/ascii
George Staikos
staikos at kde.org
Wed Apr 13 07:43:28 CEST 2005
CVS commit by staikos:
implement all of the new ascii options except:
- extraction of field names in fixed field mode
- header skip in readField()
M +63 -16 ascii.cpp 1.48
--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp #1.47:1.48
@@ -236,7 +236,14 @@ int AsciiSource::readField(double *v, co
}
- bool ok;
- int col = (int)field.toUInt(&ok);
- if (!ok) {
+ QStringList fieldList = this->fieldList();
+ int col = 0;
+ for (QStringList::ConstIterator i = fieldList.begin(); i != fieldList.end(); ++i) {
+ if (*i == field) {
+ break;
+ }
+ ++col;
+ }
+
+ if (col + 1 > fieldList.count()) {
return 0;
}
@@ -329,13 +336,5 @@ int AsciiSource::readField(double *v, co
bool AsciiSource::isValidField(const QString& field) const {
- bool ok;
-
- if (field == "INDEX") {
- return true;
- }
-
- field.toUInt(&ok);
-
- return ok && fieldList().contains(field);
+ return fieldList().contains(field);
}
@@ -371,11 +370,50 @@ static QStringList fieldListFor(const QS
}
- QRegExp re(QString("^\\s*[%1].*").arg(cfg->_delimiters));
+ rc += "INDEX";
+
+ if (cfg->_readFields) {
+ int l = cfg->_fieldsLine;
+ QString line;
+ while (!file.atEnd()) {
+ int r = file.readLine(line, 1000);
+ if (l-- == 0) {
+ if (r >= 0) {
+ if (cfg->_columnType == AsciiSource::Config::Custom && !cfg->_columnDelimiter.isEmpty()) {
+ rc += QStringList::split(QRegExp(QString("[%1]").arg(QRegExp::escape(cfg->_columnDelimiter))), line.stripWhiteSpace(), false);
+ } else if (cfg->_columnType == AsciiSource::Config::Fixed) {
+ abort(); // FIXME
+ } else {
+ rc += QStringList::split(QRegExp("[\\s]"), line.stripWhiteSpace(), false);
+ }
+ }
+ break;
+ }
+ }
+ return rc;
+ }
+
+ QRegExp re;
+ if (cfg->_columnType == AsciiSource::Config::Custom && !cfg->_columnDelimiter.isEmpty()) {
+ re = QString("^[%1]*[%2].*").arg(QRegExp::escape(cfg->_columnDelimiter)).arg(cfg->_delimiters);
+ } else {
+ re = QString("^\\s*[%1].*").arg(cfg->_delimiters);
+ }
+
bool done = false;
QString line;
+ int skip = cfg->_dataLine;
while (!file.atEnd() && !done) {
- int rc = file.readLine(line, 1000);
- if (rc > 1 && !re.exactMatch(line)) {
+ int r = file.readLine(line, 1000);
+ if (skip > 0) {
+ --skip;
+ if (r < 0) {
+ return rc;
+ }
+ continue;
+ }
+ if (r > 1 && !re.exactMatch(line)) {
done = true;
+ } else if (r < 0) {
+ return rc;
}
}
@@ -383,6 +421,6 @@ static QStringList fieldListFor(const QS
file.close();
- rc += "INDEX";
int cnt;
+ line = line.stripWhiteSpace();
if (cfg->_columnType == AsciiSource::Config::Custom && !cfg->_columnDelimiter.isEmpty()) {
cnt = QStringList::split(QRegExp(QString("[%1]").arg(QRegExp::escape(cfg->_columnDelimiter))), line, false).count();
@@ -608,6 +646,15 @@ int understands_ascii(KConfig *cfg, cons
}
+ int skip = config._dataLine;
+
while (!done) {
rc = f.readLine(s, 1000);
+ if (skip > 0) {
+ --skip;
+ if (rc <= 0) {
+ done = true;
+ }
+ continue;
+ }
if (rc <= 0) {
done = true;
More information about the Kst
mailing list