示例#1
0
 public static SourceReader From(string value)
 {
     return(new SourceReader(
                stream: SourceStream.From(value),
                position: 0
                ));
 }
示例#2
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);
        }
示例#3
0
        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));
            }
        }
示例#4
0
 private SourceReader(SourceStream stream, int position)
 {
     this.Stream   = stream;
     this.Position = position;
 }