48 lines
758 B
C#
48 lines
758 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DotnetStreams
|
|
{
|
|
public class StdInTextSource : ITextSource
|
|
{
|
|
protected bool isEof;
|
|
|
|
public virtual void Open()
|
|
{
|
|
isEof = false;
|
|
}
|
|
|
|
public virtual IEnumerable<string> ReadAll()
|
|
{
|
|
string? s = Console.ReadLine();
|
|
while (s != null)
|
|
{
|
|
yield return s;
|
|
s = Console.ReadLine();
|
|
}
|
|
isEof = true;
|
|
}
|
|
|
|
public virtual string Read()
|
|
{
|
|
string? s = Console.ReadLine();
|
|
if (s == null)
|
|
{
|
|
isEof = true;
|
|
return string.Empty;
|
|
}
|
|
else
|
|
return s;
|
|
}
|
|
|
|
public virtual bool Eof() => isEof;
|
|
|
|
public virtual void Close()
|
|
{
|
|
}
|
|
}
|
|
}
|