Example #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;
            }
        }
        public static XElement ToXElement(this LineIdentifier LineId, XName ElemName)
        {
            XElement xelem = null;

            if (LineId == null)
            {
                xelem = new XElement(ElemName, null);
            }

            else if (LineId.IntValue != null)
            {
                xelem = new XElement(ElemName,
                                     new XElement("IntValue", LineId.IntValue.Value.ToString()));
            }
            else if (LineId.GuidValue != null)
            {
                xelem = new XElement(ElemName,
                                     new XElement("GuidValue", LineId.GuidValue.Value.ToString()));
            }
            else
            {
                xelem = new XElement(ElemName, null);
            }

            return(xelem);
        }
Example #3
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));
        }
Example #4
0
        public ScanLine FindLine(LineIdentifier LineId)
        {
            var      rv   = FindLineLocation(LineId, 0);
            int      ix   = rv.Item2;
            ScanLine line = this.Lines[ix];

            return(line);
        }
 public static bool IsEqual(this LineIdentifier LineId, LineIdentifier OtherLineId)
 {
     if ((LineId == null) && (OtherLineId == null))
     {
         return(true);
     }
     else if (LineId == null)
     {
         return(false);
     }
     else if (OtherLineId == null)
     {
         return(false);
     }
     else
     {
         return(LineId.Equals(OtherLineId));
     }
 }
Example #6
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);
        }
Example #7
0
        public LineLocation FindLineLocation(LineIdentifier LineId)
        {
            LineLocation found = null;

            foreach (var loc in this)
            {
                if (loc.LineId.Equals(LineId))
                {
                    found = loc;
                    break;
                }
            }

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

            return(found);
        }
        public static LineIdentifier LineIdentifierOrDefault(
            this XElement Elem, XNamespace Namespace, LineIdentifier Default = null)
        {
            if (Elem == null)
            {
                return(Default);
            }
            else if (Elem.Value.Trim().Length == 0)
            {
                return(Default);
            }
            else
            {
                Guid?          guidValue = Elem.Element(Namespace + "GuidValue").GuidOrDefault(null);
                int?           intValue  = Elem.Element(Namespace + "IntValue").IntOrDefault(null);
                LineIdentifier lineId    = new LineIdentifier()
                {
                    GuidValue = guidValue,
                    IntValue  = intValue
                };

                return(lineId);
            }
        }
 public LineLocation(LineIdentifier LineId, int StartIndex, int EndIndex)
 {
     this.LineId     = LineId;
     this.StartIndex = StartIndex;
     this.EndIndex   = EndIndex;
 }
Example #10
0
 public TextLocation(LineIdentifier LineId, int ColumnIndex)
 {
     this.LineId      = LineId;
     this.ColumnIndex = ColumnIndex;
 }