Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- using System.Text;
- class TextReaderWithNewlines : TextReader
- {
- public TextReaderWithNewlines(TextReader inner)
- {
- this.tr = inner;
- }
- readonly TextReader tr;
- readonly StringBuilder buffer = new StringBuilder();
- string ReturnAndEmpty()
- {
- var ret = buffer.ToString();
- buffer.Length = 0;
- return ret;
- }
- public override string ReadLine()
- {
- while (true)
- {
- var as_read = tr.Read();
- if (as_read == -1)
- {
- if (buffer.Length == 0)
- return null;
- return ReturnAndEmpty();
- }
- var ch = (char)as_read;
- if (ch == '\n')
- {
- buffer.Append(ch);
- return ReturnAndEmpty();
- }
- if (ch == '\r')
- {
- if (tr.Peek() == '\n')
- {
- buffer.Append(ch);
- buffer.Append('\n');
- tr.Read();
- return ReturnAndEmpty();
- }
- }
- buffer.Append(ch);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment