Mercurial > pub > ImplabNet
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/Formats/StringScanner.cs Tue Mar 22 18:58:40 2016 +0300 @@ -0,0 +1,26 @@ +using System; + +namespace Implab.Formats { + public class StringScanner: TextScanner { + const int CHUNK_SIZE = 1024; + + readonly string m_text; + int m_pos; + + public StringScanner(string text) : base(text.Length, text.Length < CHUNK_SIZE ? text.Length : CHUNK_SIZE) { + m_text = text; + Feed(); + } + + protected override int Read(char[] buffer, int offset, int size) { + var actual = size + m_pos > m_text.Length ? m_text.Length - m_pos : size; + + m_text.CopyTo(m_pos,buffer,offset, actual); + + m_pos += actual; + + return actual; + } + } +} +