annotate Implab/JSON/JSONWriter.cs @ 106:d4e38929ce36 v2

promises refactoring
author cin
date Mon, 10 Nov 2014 18:00:28 +0300
parents d67b95eddaf4
children ffd3702968c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
1 using System;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
2 using System.Collections.Generic;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
3 using System.IO;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
4 using System.Linq;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
5 using System.Text;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
6 using System.Threading.Tasks;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
7
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
8 namespace Implab.JSON {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
9 public class JSONWriter {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
10 struct Context {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
11 public bool needComma;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
12 public JSONElementContext element;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
13 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
14 Stack<Context> m_contextStack = new Stack<Context>();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
15 Context m_context;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
16
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
17 TextWriter m_writer;
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
18 readonly bool m_indent = true;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
19 readonly int m_indentSize = 4;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
20
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
21 static readonly char [] _escapeBKS,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
22 _escapeFWD,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
23 _escapeCR,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
24 _escapeNL,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
25 _escapeTAB,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
26 _escapeSLASH,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
27 _escapeBSLASH,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
28 _escapeQ;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
29
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
30 static JSONWriter() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
31 _escapeBKS = "\\b".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
32 _escapeFWD = "\\f".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
33 _escapeCR = "\\r".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
34 _escapeNL = "\\n".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
35 _escapeTAB = "\\t".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
36 _escapeBSLASH = "\\\\".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
37 _escapeSLASH = "\\/".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
38 _escapeQ = "\\\"".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
39 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
40
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
41 public JSONWriter(TextWriter writer) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
42 Safe.ArgumentNotNull(writer, "writer");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
43
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
44 m_writer = writer;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
45 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
46
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
47 public JSONWriter(TextWriter writer, bool indent) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
48 Safe.ArgumentNotNull(writer, "writer");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
49
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
50 m_writer = writer;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
51 m_indent = indent;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
52 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
53
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
54 void WriteIndent() {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
55 if (m_indent) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
56 var indent = new char[m_contextStack.Count * m_indentSize + 1];
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
57 indent[0] = '\n';
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
58 for (int i = 1; i < indent.Length; i++)
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
59 indent[i] = ' ';
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
60 m_writer.Write(new String(indent));
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
61 } else {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
62 m_writer.Write(' ');
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
63 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
64 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
65
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
66 void WriteMemberName(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
67 Safe.ArgumentNotEmpty(name, "name");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
68 if (m_context.element != JSONElementContext.Object)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
69 OperationNotApplicable("WriteMember");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
70 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
71 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
73 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
74 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
75 Write(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
76 m_writer.Write(" : ");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
77 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
78
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
79 public void WriteValue(string name, string value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
80 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
81 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
82 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
83
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
84 public void WriteValue(string name, bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
85 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
86 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
87 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
88
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
89 public void WriteValue(string name, double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
90 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
91 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
92 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
93
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
94 public void WriteValue(string value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
95 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
96 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
97 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
98 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
99 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
100 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
101
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
102 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
103 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
104
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
105 public void WriteValue(bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
106 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
107 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
108 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
109 m_writer.Write(",");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
110 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
111
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
112 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
113 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
114 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
115
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
116 public void WriteValue(double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
117 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
118 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
119 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
120 m_writer.Write(",");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
121 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
122
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
123 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
124 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
125 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
126
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
127 public void BeginObject() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
128 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
129 OperationNotApplicable("BeginObject");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
130 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
131 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
132
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
133 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
134
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
135 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
136
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
137 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
138
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
139 m_context = new Context { element = JSONElementContext.Object, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
140 m_writer.Write("{");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
141 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
142
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
143 public void BeginObject(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
144 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
145
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
146 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
147
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
148 m_context = new Context { element = JSONElementContext.Object, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
149 m_writer.Write("{");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
150 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
151
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
152 public void EndObject() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
153 if (m_context.element != JSONElementContext.Object)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
154 OperationNotApplicable("EndArray");
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
155
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
156 m_context = m_contextStack.Pop();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
157 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
158 m_writer.Write("}");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
159 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
160
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
161 public void BeginArray() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
162 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
163 throw new InvalidOperationException();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
164 if (m_context.needComma) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
165 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
166
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
167 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
168 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
169
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
170 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
171 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
172 m_context = new Context { element = JSONElementContext.Array, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
173 m_writer.Write("[");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
174 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
175
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
176 public void BeginArray(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
177 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
178
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
179 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
180
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
181 m_context = new Context { element = JSONElementContext.Array, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
182 m_writer.Write("[");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
183 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
184
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
185 public void EndArray() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
186 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
187 OperationNotApplicable("EndArray");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
188
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
189 m_context = m_contextStack.Pop();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
190 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
191 m_writer.Write("]");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
192 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
193
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
194 void Write(bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
195 m_writer.Write(value ? "true" : "false");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
196 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
197
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
198
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
199 void Write(string value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
200 if (value == null)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
201 m_writer.Write("null");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
202
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
203 var chars = value.ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
204 m_writer.Write('"');
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
205
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
206 for (int i = 0; i < chars.Length; i++) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
207 var ch = chars[i];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
208
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
209 switch (ch) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
210 case '\b':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
211 m_writer.Write(_escapeBKS);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
212 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
213 case '\f':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
214 m_writer.Write(_escapeFWD);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
215 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
216 case '\r':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
217 m_writer.Write(_escapeCR);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
218 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
219 case '\n':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
220 m_writer.Write(_escapeNL);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
221 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
222 case '\t':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
223 m_writer.Write(_escapeTAB);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
224 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
225 case '\\':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
226 m_writer.Write(_escapeBSLASH);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
227 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
228 case '/':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
229 m_writer.Write(_escapeSLASH);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
230 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
231 case '"':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
232 m_writer.Write(_escapeQ);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
233 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
234 default:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
235 if (ch < 0x20) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
236 m_writer.Write("\\u00{0:x2}",(int)ch);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
237 } else {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
238 m_writer.Write(ch);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
239 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
240 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
241 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
242 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
243
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
244 m_writer.Write('"');
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
245 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
246
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
247 void Write(double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
248 m_writer.Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
249 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
250
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
251 void OperationNotApplicable(string opName) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
252 throw new InvalidOperationException(String.Format("The operation '{0}' isn't applicable in the context of '{1}'", opName, m_context.element ));
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
253 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
254
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
255 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
256 }