Ejemplo n.º 1
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int ptr;
            int width = GetFixedWidth();

            ArrayList          infos    = new ArrayList();
            IntervalCollection segments = new IntervalCollection();

            // accumulate segments

            ptr = 0;
            //foreach (Expression e in Expressions) {
            int count = Expressions.Count;

            for (int i = 0; i < count; ++i)
            {
                Expression e;
                if (reverse)
                {
                    e = Expressions [count - i - 1];
                }
                else
                {
                    e = Expressions [i];
                }

                AnchorInfo info = e.GetAnchorInfo(reverse);
                infos.Add(info);

                if (info.IsPosition)
                {
                    return(new AnchorInfo(this, ptr + info.Offset, width, info.Position));
                }

                if (info.IsSubstring)
                {
                    segments.Add(info.GetInterval(ptr));
                }

                if (info.IsUnknownWidth)
                {
                    break;
                }

                ptr += info.Width;
            }

            // normalize and find the longest segment

            segments.Normalize();

            Interval longest = Interval.Empty;

            foreach (Interval segment in segments)
            {
                if (segment.Size > longest.Size)
                {
                    longest = segment;
                }
            }

            // now chain the substrings that made this segment together

            if (!longest.IsEmpty)
            {
                string    str    = "";
                ArrayList strs   = new ArrayList();
                bool      ignore = false;

                ptr = 0;

                //foreach (AnchorInfo info in infos) {
                for (int i = 0; i < infos.Count; ++i)
                {
                    AnchorInfo info;

                    info = (AnchorInfo)infos[i];

                    if (info.IsSubstring && longest.Contains(info.GetInterval(ptr)))
                    {
                        //str += info.Substring;	// TODO mark subexpressions
                        strs.Add(info.Substring);
                        ignore |= info.IgnoreCase;
                    }


                    if (info.IsUnknownWidth)
                    {
                        break;
                    }

                    ptr += info.Width;
                }

                for (int i = 0; i < strs.Count; ++i)
                {
                    if (reverse)
                    {
                        str += strs [strs.Count - i - 1];
                    }
                    else
                    {
                        str += strs [i];
                    }
                }


                return(new AnchorInfo(this, longest.low, width, str, ignore));
            }

            return(new AnchorInfo(this, width));
        }
Ejemplo n.º 2
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int ptr;
            int width = GetFixedWidth();

            ArrayList          infos    = new ArrayList();
            IntervalCollection segments = new IntervalCollection();

            // accumulate segments
            ptr = 0;
            int count = Expressions.Count;

            for (int i = 0; i < count; ++i)
            {
                Expression e;
                if (reverse)
                {
                    e = Expressions [count - i - 1];
                }
                else
                {
                    e = Expressions [i];
                }

                AnchorInfo info = e.GetAnchorInfo(reverse);
                infos.Add(info);

                if (info.IsPosition)
                {
                    return(new AnchorInfo(this, ptr + info.Offset, width, info.Position));
                }

                if (info.IsSubstring)
                {
                    segments.Add(info.GetInterval(ptr));
                }

                if (info.IsUnknownWidth)
                {
                    break;
                }

                ptr += info.Width;
            }

            // normalize and find the longest segment
            segments.Normalize();

            Interval longest = Interval.Empty;

            foreach (Interval segment in segments)
            {
                if (segment.Size > longest.Size)
                {
                    longest = segment;
                }
            }

            if (longest.IsEmpty)
            {
                return(new AnchorInfo(this, width));
            }

            // now chain the substrings that made this segment together
            bool ignore    = false;
            int  n_strings = 0;

            ptr = 0;
            for (int i = 0; i < infos.Count; ++i)
            {
                AnchorInfo info = (AnchorInfo)infos [i];

                if (info.IsSubstring && longest.Contains(info.GetInterval(ptr)))
                {
                    ignore |= info.IgnoreCase;
                    infos [n_strings++] = info;
                }

                if (info.IsUnknownWidth)
                {
                    break;
                }

                ptr += info.Width;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < n_strings; ++i)
            {
                AnchorInfo info;
                if (reverse)
                {
                    info = (AnchorInfo)infos [n_strings - i - 1];
                }
                else
                {
                    info = (AnchorInfo)infos [i];
                }
                sb.Append(info.Substring);
            }

            if (sb.Length == longest.Size)
            {
                return(new AnchorInfo(this, longest.low, width, sb.ToString(), ignore));
            }
            // were the string segments overlapping?
            if (sb.Length > longest.Size)
            {
                Console.Error.WriteLine("overlapping?");
                return(new AnchorInfo(this, width));
            }
            throw new SystemException("Shouldn't happen");
        }
Ejemplo n.º 3
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int                fixedWidth         = base.GetFixedWidth();
            ArrayList          arrayList          = new ArrayList();
            IntervalCollection intervalCollection = new IntervalCollection();
            int                num   = 0;
            int                count = base.Expressions.Count;

            for (int i = 0; i < count; i++)
            {
                Expression expression;
                if (reverse)
                {
                    expression = base.Expressions[count - i - 1];
                }
                else
                {
                    expression = base.Expressions[i];
                }
                AnchorInfo anchorInfo = expression.GetAnchorInfo(reverse);
                arrayList.Add(anchorInfo);
                if (anchorInfo.IsPosition)
                {
                    return(new AnchorInfo(this, num + anchorInfo.Offset, fixedWidth, anchorInfo.Position));
                }
                if (anchorInfo.IsSubstring)
                {
                    intervalCollection.Add(anchorInfo.GetInterval(num));
                }
                if (anchorInfo.IsUnknownWidth)
                {
                    break;
                }
                num += anchorInfo.Width;
            }
            intervalCollection.Normalize();
            Interval interval = Interval.Empty;

            foreach (object obj in intervalCollection)
            {
                Interval interval2 = (Interval)obj;
                if (interval2.Size > interval.Size)
                {
                    interval = interval2;
                }
            }
            if (interval.IsEmpty)
            {
                return(new AnchorInfo(this, fixedWidth));
            }
            bool flag = false;
            int  num2 = 0;

            num = 0;
            for (int j = 0; j < arrayList.Count; j++)
            {
                AnchorInfo anchorInfo2 = (AnchorInfo)arrayList[j];
                if (anchorInfo2.IsSubstring && interval.Contains(anchorInfo2.GetInterval(num)))
                {
                    flag |= anchorInfo2.IgnoreCase;
                    arrayList[num2++] = anchorInfo2;
                }
                if (anchorInfo2.IsUnknownWidth)
                {
                    break;
                }
                num += anchorInfo2.Width;
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int k = 0; k < num2; k++)
            {
                AnchorInfo anchorInfo3;
                if (reverse)
                {
                    anchorInfo3 = (AnchorInfo)arrayList[num2 - k - 1];
                }
                else
                {
                    anchorInfo3 = (AnchorInfo)arrayList[k];
                }
                stringBuilder.Append(anchorInfo3.Substring);
            }
            if (stringBuilder.Length == interval.Size)
            {
                return(new AnchorInfo(this, interval.low, fixedWidth, stringBuilder.ToString(), flag));
            }
            if (stringBuilder.Length > interval.Size)
            {
                Console.Error.WriteLine("overlapping?");
                return(new AnchorInfo(this, fixedWidth));
            }
            throw new SystemException("Shouldn't happen");
        }