annotate Implab/Formats/StringScanner.cs @ 176:0c3c69fe225b ref20160224

rewritten the text scanner
author cin
date Tue, 22 Mar 2016 18:58:40 +0300
parents
children 76e8f2ba12b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
176
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
1 using System;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
2
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
3 namespace Implab.Formats {
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
4 public class StringScanner: TextScanner {
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
5 const int CHUNK_SIZE = 1024;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
6
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
7 readonly string m_text;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
8 int m_pos;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
9
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
10 public StringScanner(string text) : base(text.Length, text.Length < CHUNK_SIZE ? text.Length : CHUNK_SIZE) {
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
11 m_text = text;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
12 Feed();
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
13 }
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
14
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
15 protected override int Read(char[] buffer, int offset, int size) {
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
16 var actual = size + m_pos > m_text.Length ? m_text.Length - m_pos : size;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
17
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
18 m_text.CopyTo(m_pos,buffer,offset, actual);
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
19
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
20 m_pos += actual;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
21
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
22 return actual;
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
23 }
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
24 }
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
25 }
0c3c69fe225b rewritten the text scanner
cin
parents:
diff changeset
26