[Kst] extragear/graphics/kst/src/libkstmath

George Staikos staikos at kde.org
Mon Jun 19 09:33:19 CEST 2006


SVN commit 552808 by staikos:

rework the rr,gg,bb parser to be much faster, and then disable it for now.  we
need to determine the proper spec for this, write testcases, and be sure it's
what we want before enabling it.


 M  +28 -27    labelparser.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/labelparser.cpp #552807:552808
@@ -115,51 +115,52 @@
 
 
 inline QColor parseColor(const QString& txt, int *skip) {
-  QColor color;
   const int end = txt.find('}');
   if (skip) {
     *skip = end;
   }
-  
+
   if (end == -1) {
-    return color;
+    return QColor();
   }
-  
-  color.setNamedColor(txt.left(end));
+
+  const QString endPart = txt.left(end);
+
+  QColor color(endPart); // This one is slow.  If we support our own formats
+                         // outside of QColor, make sure that this is called
+                         // -after- we try our own formats.  Every cycle
+                         // counts in here.
+#if 0
+  // This is rr,gg,bb support.  I'm not sure about supporting H,S,V or even
+  // about compatibility with LaTeX so for now we don't support it.  If it's
+  // ever re-enabled, make sure that testcases are added.
   if (!color.isValid()) {
     // the color is in the format "r,g,b"
-    QStringList strColors = QStringList::split(QRegExp(","), txt.left(end), TRUE);
-    if (strColors.size() == 3) {
-      QString strColor;
-      bool ok = true;
-      int colors[3];
+    QStringList components = QStringList::split(',', endPart, true);
+    if (components.count() == 3) {
+      int colors[3] = { 0, 0, 0 };
       int base = 10;
-      
+
       // assume the colors are given as decimal numbers unless we have a hex value in the string
-      if (txt.left(end).find(QRegExp("[A-F]", FALSE)) != -1) {
+      if (endPart.find(QRegExp("[A-F]", false)) != -1) {
         base = 16;
       }
 
-      for (int i=0; i<3; i++) {
-        strColor = strColors[i];
-        strColor.stripWhiteSpace();
-        if (strColors[i].isEmpty()) {
-          colors[i] = 0;
-        } else {
-          colors[i] = strColors[i].toInt(&ok, base);
-        }
-        
-        if (!ok) {
-          break;
-        }
+      bool ok = true;
+      colors[0] = components[0].toInt(&ok, base);
+      if (ok) {
+        colors[1] = components[1].toInt(&ok, base);
       }
-      
       if (ok) {
-        color.setRgb(colors[0],colors[1],colors[2]);
+        colors[2] = components[2].toInt(&ok, base);
       }
+
+      if (ok) {
+        color.setRgb(colors[0], colors[1], colors[2]);
+      } // Should error out?
     }
   }
-  
+#endif
   return color;
 }
 


More information about the Kst mailing list