[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Fri Jan 21 13:52:08 CET 2011
SVN commit 1216111 by kuemmel:
AsciiDatasource: split out common code, the only difference is a additions isspace check for AsciiSourceConfig::Whitespace
which is a noop because white space was handled already in this case
M +33 -25 asciisource.cpp
M +3 -1 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1216110:1216111
@@ -459,12 +459,7 @@
incol = true;
++i_col;
if (i_col == col) {
- if (isdigit((unsigned char)buffer[ch]) || buffer[ch] == '-' || buffer[ch] == '.' || buffer[ch] == '+' || isspace((unsigned char)buffer[ch])) {
- v[i] = lexc.toDouble(&buffer[0] + ch);
- } else if (ch + 2 < bufread && tolower(buffer[ch]) == 'i' &&
- tolower(buffer[ch + 1]) == 'n' && tolower(buffer[ch + 2]) == 'f') {
- v[i] = INF;
- }
+ toDouble(lexc, buffer, bufread, ch, &v[i], i);
break;
}
}
@@ -473,10 +468,10 @@
}
} else if (_config._columnType == AsciiSourceConfig::Whitespace) {
const QString delimiters = _config._delimiters.value();
- for (int i = 0; i < n; i++, s++) {
+ for (int i = 0; i < n; i++, s++)
+ {
bool incol = false;
int i_col = 0;
- bool found_value = false;
v[i] = Kst::NOPOINT;
int ch;
@@ -494,29 +489,13 @@
incol = true;
++i_col;
if (i_col == col) {
- if (isdigit((unsigned char)buffer[ch]) || buffer[ch] == '-' || buffer[ch] == '.' || buffer[ch] == '+') {
- v[i] = lexc.toDouble(&buffer[0] + ch);
- found_value = true;
- } else if (ch + 2 < bufread && tolower(buffer[ch]) == 'i' &&
- tolower(buffer[ch + 1]) == 'n' && tolower(buffer[ch + 2]) == 'f') {
- v[i] = INF;
- found_value = true;
- }
+ toDouble(lexc, buffer, bufread, ch, &v[i], i);
break;
}
}
}
}
- /*
- // TODO enable by option: "Add unparsable lines as strings"
- if (!found_value) {
- if (_rowIndex.size() > s + 1) {
- QString unparsable = QString::fromAscii(&buffer[_rowIndex[s]], _rowIndex[s + 1] - _rowIndex[s]);
- _strings[QString("Unparsable %1").arg(i)] = unparsable.trimmed();
}
- }
- */
- }
} else {
return 0;
}
@@ -525,6 +504,35 @@
}
+void AsciiSource::toDouble(const LexicalCast& lexc, const char* buffer, int bufread, int ch, double* v, int row)
+{
+ const char* here = &buffer[ch];
+ if ( buffer[ch] == '-'
+ || buffer[ch] == '.'
+ || buffer[ch] == '+'
+ || isdigit((unsigned char)buffer[ch])
+ || isspace((unsigned char)buffer[ch])) {
+ *v = lexc.toDouble(&buffer[0] + ch);
+ } else if ( ch + 2 < bufread
+ && tolower(buffer[ch]) == 'i'
+ && tolower(buffer[ch + 1]) == 'n'
+ && tolower(buffer[ch + 2]) == 'f') {
+ *v = INF;
+ }
+
+#if 0
+ // TODO enable by option: "Add unparsable lines as strings"
+ else {
+ if (_rowIndex.size() > row + 1) {
+ QString unparsable = QString::fromAscii(&buffer[_rowIndex[row]], _rowIndex[row + 1] - _rowIndex[row]);
+ _strings[QString("Unparsable %1").arg(row)] = unparsable.trimmed();
+ }
+ }
+#endif
+
+}
+
+
//-------------------------------------------------------------------------------------------
QString AsciiSource::fileType() const
{
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1216110:1216111
@@ -30,8 +30,8 @@
class DataInterfaceAsciiString;
class DataInterfaceAsciiVector;
+struct LexicalCast;
-
class AsciiSource : public Kst::DataSource
{
Q_OBJECT
@@ -102,6 +102,8 @@
template<class T>
int readFromFile(QFile&, T& buffer, int start, int numberOfBytes, int maximalBytes = -1);
+ void toDouble(const LexicalCast& lexc, const char* buffer, int bufread, int ch, double* v, int row);
+
// TODO remove
friend class DataInterfaceAsciiString;
friend class DataInterfaceAsciiVector;
More information about the Kst
mailing list