Ejemplo n.º 1
0
        public void AddLine(string Text, LineIdentifier LineId)
        {
            var text = this.ScrubNewLineFromEnd(Text);

            // the start pos of the line.
            int startPos = _sb.Length;

            // add to the stream.
            _sb.Append(text + Environment.NewLine);
            _Stream = null;

            // end pos of the line.
            int endPos = _sb.Length - 1;

            // LineLocation stores the LineId of the line and its position within the stream.
            LineLocation loc = new LineLocation(LineId, startPos, endPos);

            // ScanLine stores the text of the line and its LineLocation.
            ScanLine sl = new ScanLine(text, loc);

            // list of lines.
            _Lines.Add(sl);

            // update the highest assigned lineid.
            if (LineId.IntValue.Value > _HighLineId)
            {
                _HighLineId = LineId.IntValue.Value;
            }
        }
Ejemplo n.º 2
0
        private Tuple <LineLocation, int> FindLineLocation(LineIdentifier LineId, int StartIx)
        {
            LineLocation found = null;
            int          ix    = StartIx;

            int nbrLines = this.Lines.Count;

            while (true)
            {
                if (ix >= nbrLines)
                {
                    found = null;
                    break;
                }

                ScanLine scanLine = this.Lines[ix];
                if (scanLine.LineId.Equals(LineId))
                {
                    found = scanLine.Location;
                    break;
                }

                // advance to the next line.
                ix += 1;
            }

            return(new Tuple <LineLocation, int>(found, ix));
        }
Ejemplo n.º 3
0
        public TextLocation ToTextLocation(ScanStream Lookup)
        {
            LineLocation found = null;

            // find the LineLocation on which the StreamIndex is located.
            foreach (var line in Lookup.Lines)
            {
                var loc = line.Location;
                if ((this.Value >= loc.StartIndex) && (this.Value <= loc.EndIndex))
                {
                    found = loc;
                    break;
                }
                else if (loc.StartIndex > this.Value)
                {
                    break;
                }
            }

            // location not found.
            if (found == null)
            {
                throw new ApplicationException("stream location " + this.Value.ToString() +
                                               " is not found.");
            }

            TextLocation textLoc =
                new TextLocation(found.LineId, this.Value - found.StartIndex);

            return(textLoc);
        }
Ejemplo n.º 4
0
        public LineLocation FindLineLocation(LineIdentifier LineId)
        {
            LineLocation found   = null;
            int          foundIx = 0;

            // start the search from last found line index.
            int ix = 0;

            if (this.CurrentLineIndex != null)
            {
                ix = this.CurrentLineIndex.Value;
            }

            // search from starting line forward.
            {
                var rv = this.FindLineLocation(LineId, ix);
                found   = rv.Item1;
                foundIx = rv.Item2;
            }

            // not found. seach from line 0 to the end.
            if (found == null)
            {
                var rv = this.FindLineLocation(LineId, 0);
                found   = rv.Item1;
                foundIx = rv.Item2;
            }

            // store the last found line index.
            if (found != null)
            {
                this.CurrentLineIndex = foundIx;
            }

            // error if not found.
            if (found == null)
            {
                throw new ApplicationException("Line not found");
            }

            return(found);
        }
Ejemplo n.º 5
0
 public ScanLine(string Text, LineLocation Location)
 {
     this.Text     = Text;
     this.Location = Location;
 }