[Kst] branches/work/kst/portto4/kst

Peter Kümmel syntheticpp at gmx.net
Fri Nov 30 21:05:06 UTC 2012


SVN commit 1326723 by kuemmel:

make reading of ascii date/time more flexible

 M  +4 -1      cmake/tests/datasource/ascii/CMakeLists.txt  
 M  +6 -16     src/datasources/ascii/kst_atof.cpp  
 M  +2 -3      src/datasources/ascii/kst_atof.h  
 A             tests/datasources/ascii/asciiatoftest.cpp   [License: GPL (v2+)]


--- branches/work/kst/portto4/kst/cmake/tests/datasource/ascii/CMakeLists.txt #1326722:1326723
@@ -6,14 +6,17 @@
 	add_definitions(-DKST_USE_KST_ATOF)
 endif()
 
+include_directories(${kst_dir}/src/datasources/ascii)
 
 kst_add_plugin_lib(. ascii)
 #set_target_properties(kst2_datasource_ascii_lib PROPERTIES COMPILE_DEFINITIONS KST_SMALL_PRREALLOC)
 kst_init(test_asciisource "")
-include_directories(${kst_dir}/src/datasources/ascii)
 kst_add_test(${kst_dir}/tests/datasources/ascii/asciifilebuffertest.cpp)
 kst_link(kst2_datasource_ascii_lib ${libcore} ${libmath} ${libwidgets})
 
+kst_init(test_asciiatof "")
+kst_add_test(${kst_dir}/tests/datasources/ascii/asciiatoftest.cpp)
+kst_link(kst2_datasource_ascii_lib ${libcore} ${libmath} ${libwidgets})
 
 kst_init(asciifilegenerator "")
 kst_add_files(${kst_dir}/tests/datasources/ascii/asciifilegenerator.cpp)
--- branches/work/kst/portto4/kst/src/datasources/ascii/kst_atof.cpp #1326722:1326723
@@ -124,7 +124,7 @@
 //-------------------------------------------------------------------------------------------
 LexicalCast::AutoReset::AutoReset(bool useDot)
 {
-  instance().setDecimalSeparator(useDot);
+  instance().setUseDotAsDecimalSeparator(useDot);
 }
 
 //-------------------------------------------------------------------------------------------
@@ -163,7 +163,7 @@
 }
 
 //-------------------------------------------------------------------------------------------
-void LexicalCast::setDecimalSeparator(bool useDot)
+void LexicalCast::setUseDotAsDecimalSeparator(bool useDot)
 {
   useDot ? _separator = '.' : _separator = ',';
 
@@ -191,28 +191,18 @@
   _timeFormat = format.trimmed(); // remove space at start/end
   _isTime = !format.isEmpty();
   _timeWithDate = format.contains("d") || format.contains("M") || format.contains("y");
-  if (_timeWithDate) {
-    _timeInTwoColumns = _timeFormat.contains(' ');
+  _timeFormatLength = _timeFormat.size();
   }
-} 
 
 //-------------------------------------------------------------------------------------------
 double LexicalCast::fromTime(const char* p) const
 {
-  int maxScan = 100;
-  int end = 0;
-  int columnEnd = _timeInTwoColumns ? 2 : 1;
-  int inCol = 0;
-  for (; inCol != columnEnd; end++) {
-    if (*(p + end) == ' ' || *(p + end) == '\t') {
-      inCol++;
-    }
-    if (end > maxScan)
+  for (int i = 0; i < _timeFormatLength; i++) {
+    if (*(p + i) == '\0')
       return Kst::NOPOINT;
   }
-  end--;
 
-  const QString time = QString::fromLatin1(p, end);
+  const QString time = QString::fromLatin1(p, _timeFormatLength);
   double sec = Kst::NOPOINT;
   if (_timeWithDate) {
     QDateTime t = QDateTime::fromString(time, _timeFormat);
--- branches/work/kst/portto4/kst/src/datasources/ascii/kst_atof.h #1326722:1326723
@@ -28,8 +28,7 @@
     ~AutoReset();
   };
   
-  // use second parameter when useDot is false
-  void setDecimalSeparator(bool useDot);
+  void setUseDotAsDecimalSeparator(bool useDot);
 
   char localSeparator() const;
 
@@ -50,9 +49,9 @@
   char _separator;
   QByteArray _originalLocal;
   QString _timeFormat;
+  int _timeFormatLength;
   bool _isTime;
   bool _timeWithDate;
-  bool _timeInTwoColumns;
 
   void resetLocal();
 


More information about the Kst mailing list