2 using System.Collections.Generic;
10 private StringBuilder data;
20 public string Contents
24 return data.ToString();
31 data = new StringBuilder();
34 public void BeginSection(string name)
36 WriteLine("\"" + PrepString(name) + "\"");
41 public void WritePair(string key, string value)
43 WriteLine("\"" + PrepString(key) + "\"\t\t\"" + PrepString(value) + "\"");
46 public void EndSection()
50 throw new System.Exception("Writer nesting level went out of bounds");
55 private void WriteLine(string line)
58 data.Append(line + "\n");
61 private void Tabinate()
63 for (int i = 0; i < level; i++)
69 private string PrepString(string text)
71 /* Escape all escaped newlines (so they can be unescaped later) */
72 text = text.Replace("\\n", "\\\\n");
73 /* Escape all literal newlines */
74 text = text.Replace("\n", "\\n");
75 text = text.Replace("\r", "");
76 /* Remove escaped quotations */
77 text = text.Replace("\\\"", "\"");
78 /* Replace all quotations with escaped ones now */
79 text = text.Replace("\"", "\\\"");