public static SourceExtent From(SourceChar @char) { return(new SourceExtent( startPosition: @char.Position, endPosition: @char.Position, text: new string(@char.Value, 1) )); }
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)); } }