Advertisement
Guest User

Parse 2.0

a guest
Feb 2nd, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Node ParseText1(string text)
  2. {
  3. List<Node> last = new List<Node>();
  4. Node cur = new Node();
  5. string buf = "";
  6. bool quotes = false;
  7. for (int i = 1; i < text.Length - 1; i++)
  8. {
  9. char c = text[i];
  10. if (c == '{')
  11. {
  12. last.Add(cur);
  13. cur = new Node();
  14. continue;
  15. }
  16. if (c == '}')
  17. {
  18. if (!(text[i - 1] == '}'))
  19. {
  20. cur.Nodes.Add(new Node() { Value = buf });
  21. buf = "";
  22. }
  23. last.Last().Nodes.Add(cur);
  24. cur = last.Last();
  25. last.Remove(cur);
  26. continue;
  27. }
  28. if (c == '"')
  29. quotes = !quotes;
  30. if (!(text[i - 1] == '}'))
  31. {
  32. if (c == ',' && !quotes)
  33. {
  34. cur.Nodes.Add(new Node() { Value = buf });
  35. buf = "";
  36. }
  37. else
  38. {
  39. buf += c;
  40. }
  41. }
  42. }
  43. return cur;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement