Ejemplo n.º 1
0
 public Range(int start, int end, GroupMap parent, GrepCaptureGroup group)
 {
     Start     = Math.Min(start, end);
     End       = Math.Max(start, end);
     parentMap = parent;
     Group     = group;
 }
Ejemplo n.º 2
0
            private void Insert(GrepCaptureGroup group)
            {
                int startIndex = group.StartLocation - start;
                int endIndex   = startIndex + group.Length;

                //gggggg
                //xxxxxx
                var replace = ranges.FirstOrDefault(r => r.Start == startIndex && r.End == endIndex);

                if (replace != null)
                {
                    ranges.Remove(replace);
                    ranges.Add(new Range(startIndex, endIndex, this, group));
                }
                else
                {
                    //gg
                    //xxxxxx
                    var head = ranges.FirstOrDefault(r => r.Start == startIndex && r.End > endIndex);
                    if (head != null)
                    {
                        ranges.Remove(head);
                        ranges.Add(new Range(startIndex, endIndex, this, group));
                        ranges.Add(new Range(endIndex, head.End, this, head.Group));
                    }
                    else
                    {
                        //    gg
                        //xxxxxx
                        var tail = ranges.FirstOrDefault(r => r.Start < startIndex && r.End == endIndex);
                        if (tail != null)
                        {
                            ranges.Remove(tail);
                            ranges.Add(new Range(tail.Start, startIndex, this, tail.Group));
                            ranges.Add(new Range(startIndex, endIndex, this, group));
                        }
                        else
                        {
                            //  gg
                            //xxxxxx
                            var split = ranges.FirstOrDefault(r => r.Start <startIndex && r.End> endIndex);
                            if (split != null)
                            {
                                ranges.Remove(split);
                                ranges.Add(new Range(split.Start, startIndex, this, split.Group));
                                ranges.Add(new Range(startIndex, endIndex, this, group));
                                ranges.Add(new Range(endIndex, split.End, this, split.Group));
                            }
                            else
                            {
                                //   gggg
                                //xxxxxyyyyy
                                var spans = ranges.Where(r => (r.Start < startIndex && r.End < endIndex) ||
                                                         (r.Start > startIndex && r.End > endIndex)).OrderBy(r => r.Start).ToList();

                                if (spans.Count == 2)
                                {
                                    ranges.Remove(spans[0]);
                                    ranges.Remove(spans[1]);
                                    ranges.Add(new Range(spans[0].Start, startIndex, this, spans[0].Group));
                                    ranges.Add(new Range(startIndex, endIndex, this, group));
                                    ranges.Add(new Range(endIndex, spans[1].End, this, spans[1].Group));
                                }
                            }
                        }
                    }
                }
            }