public void TestReadToEnd([Values(EndOfLine.CR, EndOfLine.CRLF, EndOfLine.LF)] EndOfLine eol) { var s = string.Format("hello{0}world{0}", eol.AsNewline()); using (var reader = new StackBufferedTextReader(new StringReader(s))) { Assert.That(reader.ReadToEnd(), Is.EqualTo(s)); Assert.That(reader.ReadToEnd(), Is.EqualTo("")); } }
public void TestRevert() { const string s = "world"; using (var reader = new StackBufferedTextReader(new StringReader(s))) { reader.Push(' '); reader.Push("hello"); Assert.That(reader.ReadToEnd(), Is.EqualTo("hello world")); } }
public void TestRead2() { const string s = "hello"; using (var reader = new StackBufferedTextReader(new StringReader(s))) { var buffer = new char[4]; Assert.That(reader.Read(buffer, 0, buffer.Length), Is.EqualTo(buffer.Length)); Assert.That(new string(buffer), Is.EqualTo("hell")); Assert.That(reader.Read(buffer, 2, 2), Is.EqualTo(1)); Assert.That(new string(buffer)[2], Is.EqualTo('o')); } }
public void TestRead1() { const string s = "hello"; using (var reader = new StackBufferedTextReader(new StringReader(s))) { Assert.That(reader.Read(), Is.EqualTo((int)'h')); Assert.That(reader.Read(), Is.EqualTo((int)'e')); Assert.That(reader.Read(), Is.EqualTo((int)'l')); Assert.That(reader.Read(), Is.EqualTo((int)'l')); Assert.That(reader.Read(), Is.EqualTo((int)'o')); Assert.That(reader.Read(), Is.EqualTo(-1)); } }
private CsvReader(TextReader reader, CsvReaderSettings settings, bool disposed) { if (reader == null) { throw new ArgumentNullException("reader"); } settings = settings ?? new CsvReaderSettings(); this.reader = reader is StackBufferedTextReader ? (StackBufferedTextReader)reader : new StackBufferedTextReader(reader); this.delimiter = settings.RecordDelimiter.AsNewline(); this.delimiterFirst = this.delimiter[0]; this.separator = settings.FieldDelimiter; this.separatorFirst = this.separator[0]; this.quotation = settings.QuotationCharacter; this.buffer = new char[Math.Max(this.delimiter.Length, this.separator.Length)]; this.disposed = disposed; }