##// END OF EJS Templates
fixed JSON parser error when parsing escaped double quote symbol
cin -
r226:9428ea36838e v2
parent child
Show More
@@ -1,52 +1,52
1 1 using Implab;
2 2 using Implab.Formats;
3 3 using System;
4 4 using System.Collections.Generic;
5 5 using System.Diagnostics;
6 6 using System.Linq;
7 7 using System.Text;
8 8 using System.Threading.Tasks;
9 9
10 10 namespace Implab.Formats.JSON {
11 11 /// <summary>
12 12 /// Класс для прСобразования экранированной строки JSON
13 13 /// </summary>
14 14 static class StringTranslator {
15 15 static readonly char[] _escMap;
16 16 static readonly int[] _hexMap;
17 17
18 18 static StringTranslator() {
19 var chars = new char[] { 'b', 'f', 't', 'r', 'n', '\\', '/' };
20 var vals = new char[] { '\b', '\f', '\t', '\r', '\n', '\\', '/' };
19 var chars = new char[] { 'b', 'f', 't', 'r', 'n', '\\', '/', '"' };
20 var vals = new char[] { '\b', '\f', '\t', '\r', '\n', '\\', '/', '"' };
21 21
22 22 _escMap = new char[chars.Max() + 1];
23 23
24 24 for (int i = 0; i < chars.Length; i++)
25 25 _escMap[chars[i]] = vals[i];
26 26
27 27 var hexs = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F' };
28 28 var ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15 };
29 29
30 30 _hexMap = new int[hexs.Max() + 1];
31 31
32 32 for (int i = 0; i < hexs.Length; i++)
33 33 _hexMap[hexs[i]] = ints[i];
34 34
35 35 }
36 36
37 37 internal static char TranslateEscapedChar(char symbol) {
38 38 return _escMap[symbol];
39 39 }
40 40
41 41 internal static char TranslateHexUnicode(char[] symbols, int offset) {
42 42 Debug.Assert(symbols != null);
43 43 Debug.Assert(symbols.Length - offset >= 4);
44 44
45 45 int value = (_hexMap[symbols[offset]] << 12)
46 46 | (_hexMap[symbols[offset + 1]] << 8)
47 47 | (_hexMap[symbols[offset + 2]] << 4)
48 48 | (_hexMap[symbols[offset + 3]]);
49 49 return (char)value;
50 50 }
51 51 }
52 52 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now