#include "Lsys.hpp"

  QString iterate(QString tree)
  {
    int curly_left = tree.indexOf('{');
    int curly_right = tree.lastIndexOf('}');
    int i = curly_right + 1;
    while (i < tree.length())
    {
      int key = curly_left + 1;  //start of the rules, the key
      //for every rules
      while (key < curly_right)
      {
        int colon = key + 1;                     //the value, while the key is one char len
        int semicolon = tree.indexOf(";",colon);    //end of the value
        if (tree.at(i) == tree.at(key))
        {
          int length = semicolon-colon - 1;      //length of the value
          tree.replace(i, 1, tree.mid(colon+1, length));
          key = curly_right;
          i = i + length - 1;                       //minus one because there is a +1 below
        }
        else
        {
          key = semicolon + 1;
        }
      }
      i++;
    }
    return tree;
  }

