Beispiel #1
0
            /// <summary>
            /// Splits with the specified offset.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <returns>
            /// The latter InsertSegment resulted from this split.
            /// </returns>
            public InsertSegment Split(int offset)
            {
                if (this.Offset >= offset || offset >= this.Offset + this.Length)
                {
                    throw new ArgumentOutOfRangeException();
                }

                var result = new InsertSegment(
                    this.Event,
                    offset,
                    this.Offset + this.Length - offset,
                    this.Text.Substring(offset - this.Offset));

                // Adjust my own length.
                this.Length = offset - this.Offset;
                this.Text   = this.Text.Substring(0, offset - this.Offset);

                return(result);
            }
Beispiel #2
0
        /// <summary>
        /// Processes the insert change for Type I backtracking detection.
        /// </summary>
        /// <param name="anEvent">An event.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="insertedText">The inserted text.</param>
        private void ProcessInsertType1(Event anEvent, int offset, string insertedText)
        {
            // Iterate the segments list
            List <InsertSegment> list             = this.InsertSegments[this.CurrentFile];
            InsertSegment        segmentToBeAdded = new InsertSegment(anEvent, offset, insertedText.Length, insertedText);
            bool added = false;

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].EndOffset <= offset)
                {
                    continue;
                }
                else if (list[i].Offset < offset && offset < list[i].EndOffset)
                {
                    list.Insert(i + 1, list[i].Split(offset));
                    list.Insert(i + 1, segmentToBeAdded);
                    added = true;
                    ++i;
                }
                else if (offset <= list[i].Offset)
                {
                    if (!added)
                    {
                        list.Insert(i, segmentToBeAdded);
                        added = true;
                        ++i;
                    }

                    list[i].Offset += insertedText.Length;
                }
                else
                {
                    Debug.Assert(false, "Invalid control flow");
                }
            }

            if (!added)
            {
                list.Add(segmentToBeAdded);
                added = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Filters the given type1 backtracking instance with various heuristics.
        /// </summary>
        /// <param name="insertSegment">The insert segment.</param>
        /// <param name="deletedText">The deleted text.</param>
        /// <returns>
        /// true if this instance should be detected, false otherwise.
        /// </returns>
        private bool FilterType1Backtracking(InsertSegment insertSegment, string deletedText)
        {
            if (deletedText == null)
            {
                return(false);
            }

            // Size heuristic.
            if (deletedText.Trim().Length < Type1SizeThreshold)
            {
                return(false);
            }

            // Exclude "import" statements
            if (deletedText.Trim().StartsWith("import"))
            {
                return(false);
            }

            return(true);
        }