public static SourceReader From(string value) { return(new SourceReader( stream: SourceStream.From(value), position: 0 )); }
private bool PopulateBufferChar() { // read the next char from the stream var streamRead = this.BaseReader.Read(); if (streamRead == -1) { return(false); } var streamChar = (char)streamRead; // append a char to the buffer var lastChar = (this.Buffer?.Count == 0) ? null : this.Buffer[this.Buffer.Count - 1]; var nextChar = new SourceChar( SourceStream.GetNextPosition(lastChar, streamChar), streamChar ); this.Buffer.Add(nextChar); return(true); }
private static SourcePosition GetNextPosition(SourceChar lastChar, char nextChar) { var lastPosition = lastChar?.Position; if (lastPosition == null) { return(SourceStream.StartOfStream()); } switch (lastChar.Value) { case '\r': return((nextChar == '\n') ? SourceStream.MoveToNext(lastPosition) : SourceStream.StartNewLine(lastPosition)); case '\n': return(SourceStream.StartNewLine(lastPosition)); default: return(SourceStream.MoveToNext(lastPosition)); } }
private SourceReader(SourceStream stream, int position) { this.Stream = stream; this.Position = position; }