[Kst] kdeextragear-2/kst/kst/datasources/ascii

George Staikos staikos at kde.org
Mon Apr 11 15:39:22 CEST 2005


CVS commit by staikos: 

factor regexp creation out of the loop


  M +11 -10    ascii.cpp   1.44


--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp  #1.43:1.44
@@ -577,4 +577,13 @@ int understands_ascii(KConfig *cfg, cons
     bool done = false;
 
+    QRegExp commentRE, dataRE;
+    if (config._columnType == AsciiSource::Config::Custom && !config._columnDelimiter.isEmpty()) {
+      commentRE = QString("^[%1]*[%2].*").arg(config._columnDelimiter).arg(config._delimiters);
+      dataRE = QString("^[%1]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+").arg(config._columnDelimiter);
+    } else {
+      commentRE = QString("^\\s*[%1].*").arg(config._delimiters);
+      dataRE = QString("^[\\s]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+");
+    }
+
     while (!done) {
       rc = f.readLine(s, 1000);
@@ -583,15 +592,7 @@ int understands_ascii(KConfig *cfg, cons
       } else if (rc == 1) {
         // empty line; do nothing
-      } 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)) {
+      } else if (commentRE.exactMatch(s)) {
         // comment; do nothing
-      } 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)) {
+      } else if (dataRE.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