Mercurial > pub > ImplabNet
comparison Implab/Formats/JSON/JsonTextScanner.cs @ 228:6fa235c5a760 v2
Rewritten JsonScanner, JsonParser, fixed naming style
author | cin |
---|---|
date | Tue, 12 Sep 2017 01:19:12 +0300 |
parents | |
children | 5f7a3e1d32b9 |
comparison
equal
deleted
inserted
replaced
227:8d5de4eb9c2c | 228:6fa235c5a760 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.IO; | |
4 using System.Linq; | |
5 using System.Text; | |
6 using System.Threading.Tasks; | |
7 | |
8 namespace Implab.Formats.Json { | |
9 public class JsonTextScanner : JsonScanner { | |
10 const int _bufferSize = 4096; | |
11 readonly TextReader m_reader; | |
12 | |
13 JsonTextScanner(TextReader reader, char[] buffer) : base(buffer, 0, 0) { | |
14 m_reader = reader; | |
15 } | |
16 | |
17 protected override int Read(char[] buffer, int offset, int size) { | |
18 return m_reader.Read(buffer, offset, size); | |
19 } | |
20 | |
21 public static JsonTextScanner Create(string file, Encoding encoding) { | |
22 return new JsonTextScanner(new StreamReader(file, encoding), new char[_bufferSize]); | |
23 } | |
24 | |
25 public static JsonTextScanner Create(string file) { | |
26 return new JsonTextScanner(new StreamReader(file), new char[_bufferSize]); | |
27 } | |
28 | |
29 public static JsonTextScanner Create(Stream stream, Encoding encoding) { | |
30 return new JsonTextScanner(new StreamReader(stream, encoding), new char[_bufferSize]); | |
31 } | |
32 | |
33 public static JsonTextScanner Create(Stream stream) { | |
34 return new JsonTextScanner(new StreamReader(stream), new char[_bufferSize]); | |
35 } | |
36 | |
37 public static JsonTextScanner Create(TextReader reader) { | |
38 Safe.ArgumentNotNull(reader, nameof(reader)); | |
39 return new JsonTextScanner(reader, new char[_bufferSize]); | |
40 } | |
41 | |
42 protected override void Dispose(bool disposing) { | |
43 if (disposing) | |
44 Safe.Dispose(m_reader); | |
45 | |
46 base.Dispose(disposing); | |
47 } | |
48 } | |
49 } |