[Kst] kdeextragear-2/kst

George Staikos staikos at kde.org
Wed Dec 15 08:22:47 CET 2004


CVS commit by staikos: 

parse scalars and strings out


  M +29 -5     kst/labelparser.cpp   1.10
  M +2 -0      kst/labelparser.h   1.8
  M +38 -0     tests/testlabelparser.cpp   1.7


--- kdeextragear-2/kst/kst/labelparser.cpp  #1.9:1.10
@@ -26,5 +26,5 @@ using namespace Label;
 
 Chunk::Chunk(Chunk *parent, VOffset dir, bool group)
-: next(0L), prev(0L), up(0L), down(0L), symbol(false), group(group), vOffset(dir) {
+: next(0L), prev(0L), up(0L), down(0L), symbol(false), scalar(false), group(group), vOffset(dir) {
   assert(parent || vOffset == None);
   if (parent) {  // attach and inherit
@@ -70,4 +70,9 @@ Chunk::~Chunk() {
 
 
+bool Chunk::locked() const {
+  return scalar || group;
+}
+
+
 Parsed::Parsed() : chunk(0L) {
 }
@@ -81,5 +86,5 @@ Parsed::~Parsed() {
 
 inline void setSymbolChar(QChar c, Chunk **tail) {
-  if (*tail && ((*tail)->symbol || (*tail)->text.isEmpty())) {
+  if (*tail && !(*tail)->locked() && ((*tail)->symbol || (*tail)->text.isEmpty())) {
     (*tail)->text += c;
     (*tail)->symbol = true;
@@ -94,5 +99,5 @@ inline void setSymbolChar(QChar c, Chunk
 
 inline void setNormalChar(QChar c, Chunk **tail) {
-  if (*tail && !(*tail)->symbol) {
+  if (*tail && !(*tail)->locked() && !(*tail)->symbol) {
     (*tail)->text += c;
   } else {
@@ -322,7 +327,26 @@ static Chunk *parseInternal(Chunk *ctail
         }
         break;
-        // FIXME: do scalar replacement
+      case '[':
+        {
+          int pos = txt.find(']', i + 1);
+          if (pos < 0 || pos == int(i) + 1) {
+            return 0L;
+          }
+          
+          if (ctail->locked() || !ctail->text.isEmpty()) {
+            if (ctail->vOffset != Chunk::None) {
+              ctail = new Chunk(ctail->prev);
+            } else {
+              ctail = new Chunk(ctail);
+            }
+          }
+
+          ctail->text = txt.mid(i + 1, pos - i - 1);
+          ctail->scalar = true;
+          i = uint(pos);
+        }
+        break;
       default:
-        if (ctail->vOffset != Chunk::None && (!ctail->text.isEmpty() || ctail->group)) {
+        if (ctail->vOffset != Chunk::None && (!ctail->text.isEmpty() || ctail->locked())) {
           ctail = new Chunk(ctail->prev);
         }

--- kdeextragear-2/kst/kst/labelparser.h  #1.7:1.8
@@ -46,6 +46,8 @@ namespace Label {
     ~Chunk();
 
+    bool locked() const;
     Chunk *next, *prev, *up, *down;
     bool symbol : 1;
+    bool scalar : 1;
     bool group : 1;
     VOffset vOffset : 2;

--- kdeextragear-2/kst/tests/testlabelparser.cpp  #1.6:1.7
@@ -277,4 +277,42 @@ void doTests() {
   delete parsed;
 
+  parsed = Label::parse("[ a ^label ]");
+  doTest(parsed != 0L);
+  c = parsed->chunk;
+  doTest(c->next == 0L);
+  doTest(c->up == 0L);
+  doTest(c->down == 0L);
+  doTest(c->text == " a ^label ");
+  doTest(c->scalar);
+  delete parsed;
+
+  parsed = Label::parse("[x]^[a]_[b][c]");
+  doTest(parsed != 0L);
+  c = parsed->chunk;
+  doTest(c->next != 0L);
+  doTest(c->up != 0L);
+  doTest(c->down != 0L);
+  doTest(c->text == "x");
+  doTest(c->scalar);
+  c = c->up;
+  doTest(c->next == 0L);
+  doTest(c->up == 0L);
+  doTest(c->down == 0L);
+  doTest(c->text == "a");
+  doTest(c->scalar);
+  c = c->prev->down;
+  doTest(c->next == 0L);
+  doTest(c->up == 0L);
+  doTest(c->down == 0L);
+  doTest(c->text == "b");
+  doTest(c->scalar);
+  c = c->prev->next;
+  doTest(c->next == 0L);
+  doTest(c->up == 0L);
+  doTest(c->down == 0L);
+  doTest(c->text == "c");
+  doTest(c->scalar);
+  delete parsed;
+
 }
 





More information about the Kst mailing list