CanonSharp/CanonSharp.Common/Reader/StringReader.cs
jackfiled 3c0d51cec5 feat: 正则词法识别器 (#1)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/1
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-07-29 16:59:29 +08:00

34 lines
589 B
C#

using CanonSharp.Common.Abstractions;
namespace CanonSharp.Common.Reader;
public class StringReader(string source) : ISourceReader
{
private int _pos;
public char Read()
{
if (_pos >= source.Length)
{
throw new InvalidOperationException();
}
char result = source[_pos];
_pos += 1;
return result;
}
public bool TryPeek(out char c)
{
if (_pos < source.Length)
{
c = source[_pos];
return true;
}
c = char.MinValue;
return false;
}
}