private StringReproduction ReadText() { StringReproduction Node = new StringReproduction(); StringBuilder str = new StringBuilder("", 25); bool Check; if (Pos >= TextChars.Length) { Check = false; Node.AddElement(""); } else { Check = true; while (Check) { switch (TextChars[Pos]) { case '{': goto case '['; case '[': Node.AddElement(str.ToString()); str.Remove(0, str.Length); Node.AddElement(ReadBranch()); break; case '^': // экранирование символов if ((Pos + 1) < TextChars.Length) { Pos++; str.Append(TextChars[Pos]); } else str.Append(TextChars[Pos]); break; case '<': // проверяем на глобальное экранирование текста if ((Pos + 2) < TextChars.Length) { if ((TextChars[Pos + 1] == '<') && (TextChars[Pos + 2] == '<')) str.Append(ReadInvariableText()); else str.Append(TextChars[Pos]); } else str.Append(TextChars[Pos]); break; case '%': goto case '#'; case '#': if ((Pos + 1) < TextChars.Length) { if (TextChars[Pos + 1] == ']') { Pos++; goto case ']'; } else str.Append(TextChars[Pos]); } else str.Append(TextChars[Pos]); break; case '|': goto case ']'; case '}': goto case ']'; case ']': Check = false; Pos--; Node.AddElement(str.ToString()); str.Remove(0, str.Length); break; default: str.Append(TextChars[Pos]); break; } Pos++; if (Pos >= TextChars.Length) { Check = false; Node.AddElement(str.ToString()); } } } return Node; }
private StringReproduction ReadBranch() { StringReproduction Node; switch (TextChars[Pos]) { case '{': Node = new StringReproduction(1); Pos++; break; case '[': if ((Pos + 1) < TextChars.Length) { switch (TextChars[Pos + 1]) { case '%': Node = new StringReproduction(3); Pos = Pos + 2; break; case '#': Node = new StringReproduction(4); Pos = Pos + 2; break; default: Node = new StringReproduction(2); Pos++; break; } } else { Node = new StringReproduction(2); Pos++; } break; default: Node = new StringReproduction(); break; } bool Check = true; while (Check) { Node.AddElement(ReadText()); if (Pos >= TextChars.Length) Check = false; else { if (TextChars[Pos] != '|') Check = false; else Pos++; } } return Node; }