comparison Implab/JSON/JSONWriter.cs @ 119:2573b562e328 v2

Promises rewritten, added improved version of AsyncQueue
author cin
date Sun, 11 Jan 2015 19:13:02 +0300
parents e046a94eecb1
children 0fa293bb1351
comparison
equal deleted inserted replaced
118:e046a94eecb1 119:2573b562e328
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.IO; 3 using System.IO;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7 4
8 namespace Implab.JSON { 5 namespace Implab.JSON {
9 public class JSONWriter { 6 public class JSONWriter {
10 struct Context { 7 struct Context {
11 public bool needComma; 8 public bool needComma;
21 static readonly char [] _escapeBKS, 18 static readonly char [] _escapeBKS,
22 _escapeFWD, 19 _escapeFWD,
23 _escapeCR, 20 _escapeCR,
24 _escapeNL, 21 _escapeNL,
25 _escapeTAB, 22 _escapeTAB,
26 _escapeSLASH,
27 _escapeBSLASH, 23 _escapeBSLASH,
28 _escapeQ; 24 _escapeQ;
29 25
30 static JSONWriter() { 26 static JSONWriter() {
31 _escapeBKS = "\\b".ToCharArray(); 27 _escapeBKS = "\\b".ToCharArray();
32 _escapeFWD = "\\f".ToCharArray(); 28 _escapeFWD = "\\f".ToCharArray();
33 _escapeCR = "\\r".ToCharArray(); 29 _escapeCR = "\\r".ToCharArray();
34 _escapeNL = "\\n".ToCharArray(); 30 _escapeNL = "\\n".ToCharArray();
35 _escapeTAB = "\\t".ToCharArray(); 31 _escapeTAB = "\\t".ToCharArray();
36 _escapeBSLASH = "\\\\".ToCharArray(); 32 _escapeBSLASH = "\\\\".ToCharArray();
37 _escapeSLASH = "\\/".ToCharArray();
38 _escapeQ = "\\\"".ToCharArray(); 33 _escapeQ = "\\\"".ToCharArray();
39 } 34 }
40 35
41 public JSONWriter(TextWriter writer) { 36 public JSONWriter(TextWriter writer) {
42 Safe.ArgumentNotNull(writer, "writer"); 37 Safe.ArgumentNotNull(writer, "writer");
203 } 198 }
204 199
205 var chars = value.ToCharArray(); 200 var chars = value.ToCharArray();
206 m_writer.Write('"'); 201 m_writer.Write('"');
207 202
203 // Analysis disable once ForCanBeConvertedToForeach
208 for (int i = 0; i < chars.Length; i++) { 204 for (int i = 0; i < chars.Length; i++) {
209 var ch = chars[i]; 205 var ch = chars[i];
210 206
211 switch (ch) { 207 switch (ch) {
212 case '\b': 208 case '\b':