##// END OF EJS Templates
Added SerializationHelpers.SerializeToFile method
Added SerializationHelpers.SerializeToFile method

File last commit:

r228:6fa235c5a760 v2
r231:3eaa9372c754 v2
Show More
StringTranslator.cs
52 lines | 1.8 KiB | text/x-csharp | CSharpLexer
/ Implab / Formats / JSON / StringTranslator.cs
cin
JSON moved to Formats namespace...
r163 using Implab;
cin
rewritten the text scanner
r176 using Implab.Formats;
cin
JSON moved to Formats namespace...
r163 using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
cin
Rewritten JsonScanner, JsonParser, fixed naming style
r228 namespace Implab.Formats.Json {
cin
JSON moved to Formats namespace...
r163 /// <summary>
/// Класс для преобразования экранированной строки JSON
/// </summary>
cin
refactoring complete, JSONParser rewritten
r180 static class StringTranslator {
cin
JSON moved to Formats namespace...
r163 static readonly char[] _escMap;
static readonly int[] _hexMap;
static StringTranslator() {
cin
fixed JSON parser error when parsing escaped double quote symbol
r226 var chars = new char[] { 'b', 'f', 't', 'r', 'n', '\\', '/', '"' };
var vals = new char[] { '\b', '\f', '\t', '\r', '\n', '\\', '/', '"' };
cin
JSON moved to Formats namespace...
r163
_escMap = new char[chars.Max() + 1];
for (int i = 0; i < chars.Length; i++)
_escMap[chars[i]] = vals[i];
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' };
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 };
_hexMap = new int[hexs.Max() + 1];
for (int i = 0; i < hexs.Length; i++)
_hexMap[hexs[i]] = ints[i];
}
internal static char TranslateEscapedChar(char symbol) {
return _escMap[symbol];
}
internal static char TranslateHexUnicode(char[] symbols, int offset) {
Debug.Assert(symbols != null);
Debug.Assert(symbols.Length - offset >= 4);
int value = (_hexMap[symbols[offset]] << 12)
| (_hexMap[symbols[offset + 1]] << 8)
| (_hexMap[symbols[offset + 2]] << 4)
| (_hexMap[symbols[offset + 3]]);
return (char)value;
}
}
}