[Kst] kdeextragear-2/kst/kst/datasources/ascii
George Staikos
staikos at kde.org
Mon Apr 11 15:25:03 CEST 2005
CVS commit by staikos:
this should finish up the data formatting section of ascii settings. There is
no detection code for Fixed Width Columns though. Nicolas' did not have any
such code either.
M +21 -13 ascii.cpp 1.43
--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp #1.42:1.43
@@ -353,6 +353,4 @@ static QStringList fieldListFor(const QS
QStringList rc;
QFile file(filename);
- bool done = false;
- QString line;
if (!file.open(IO_ReadOnly)) {
@@ -361,4 +359,6 @@ static QStringList fieldListFor(const QS
QRegExp re(QString("^\\s*[%1].*").arg(cfg->_delimiters));
+ bool done = false;
+ QString line;
while (!file.atEnd() && !done) {
int rc = file.readLine(line, 1000);
@@ -372,8 +372,10 @@ static QStringList fieldListFor(const QS
rc += "INDEX";
int cnt;
- if (cfg->_columnDelimiter.isEmpty()) {
- cnt = QStringList::split(QRegExp("\\s"), line, false).count();
- } else {
+ if (cfg->_columnType == AsciiSource::Config::Custom && !cfg->_columnDelimiter.isEmpty()) {
cnt = QStringList::split(QRegExp(QString("[%1]").arg(cfg->_columnDelimiter)), line, false).count();
+ } else if (cfg->_columnType == AsciiSource::Config::Fixed) {
+ cnt = line.length() / cfg->_columnWidth;
+ } else {
+ cnt = QStringList::split(QRegExp("\\s"), line, false).count();
}
for (int i = 1; i <= cnt; ++i) {
@@ -559,9 +561,9 @@ QStringList provides_ascii() {
int understands_ascii(KConfig *cfg, const QString& filename) {
QFile f(filename);
+ AsciiSource::Config config;
+ config.read(cfg, filename);
- cfg->setGroup("ASCII General");
- QString pattern = cfg->readEntry("Filename Pattern", QString::null);
- if (!pattern.isEmpty()) {
- QRegExp filenamePattern(pattern);
+ if (!config._fileNamePattern.isEmpty()) {
+ QRegExp filenamePattern(config._fileNamePattern);
filenamePattern.setWildcard(true);
if (filenamePattern.exactMatch(filename)) {
@@ -570,6 +572,4 @@ int understands_ascii(KConfig *cfg, cons
}
- QString delimiters = QRegExp::escape(cfg->readEntry("Comment Delimiters", DEFAULT_DELIMITERS));
-
if (f.open(IO_ReadOnly)) {
QString s;
@@ -583,7 +583,15 @@ int understands_ascii(KConfig *cfg, cons
} else if (rc == 1) {
// empty line; do nothing
- } else if (QRegExp(QString("^\\s*[%1].*").arg(delimiters)).exactMatch(s)) {
+ } else if (config._columnType == AsciiSource::Config::Whitespace &&
+ QRegExp(QString("^\\s*[%1].*").arg(config._delimiters)).exactMatch(s)) {
+ } else if (config._columnType == AsciiSource::Config::Custom &&
+ QRegExp(QString("^[%1]*[%2].*").arg(config._columnDelimiter).arg(config._delimiters)).exactMatch(s)) {
// comment; do nothing
- } else if (QRegExp("^[\\s]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+").exactMatch(s)) {
+ } else if (config._columnType == AsciiSource::Config::Whitespace &&
+ QRegExp("^[\\s]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+").exactMatch(s)) {
+ // a number - this may be an ascii file - assume that it is
+ return QFile::exists(s.stripWhiteSpace()) ? 49 : 75;
+ } else if (config._columnType == AsciiSource::Config::Custom &&
+ QRegExp(QString("^[%1]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+").arg(config._columnDelimiter)).exactMatch(s)) {
// a number - this may be an ascii file - assume that it is
return QFile::exists(s.stripWhiteSpace()) ? 49 : 75;
More information about the Kst
mailing list