/*
____________________________________________________
|                                                  |
|          author => Martin Robinson               |
|                                                  |
|          you are authorised to use               |
|          this code in the way you                |
|          like, commercial, personal,             |
|          opensource or anything else             |
|          you could imagine. But you              |
|          are not authorised to own               |
|          copyright on this work                  |
|__________________________________________________|
____________________________________________________
|                                                  |
|           Lsystem                                |
|           language C++                           |
|           Library Qt4.4                          |
|__________________________________________________|
*/
#include "Lsys.hpp"

  void 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 ;
  }

