예제 #1
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int width = GetFixedWidth();

            if (Minimum == 0)
            {
                return(new AnchorInfo(this, width));
            }

            AnchorInfo info = Expression.GetAnchorInfo(reverse);

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

            if (info.IsSubstring)
            {
                if (info.IsComplete)
                {
                    string str = "";
                    for (int i = 0; i < Minimum; ++i)
                    {
                        str += info.Substring;
                    }

                    return(new AnchorInfo(this, 0, width, str, info.IgnoreCase));
                }

                return(new AnchorInfo(this, info.Offset, width, info.Substring, info.IgnoreCase));
            }

            return(new AnchorInfo(this, width));
        }
예제 #2
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int width = GetFixedWidth();

            if (Minimum == 0)
            {
                return(new AnchorInfo(this, width));
            }

            AnchorInfo info = Expression.GetAnchorInfo(reverse);

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

            if (info.IsSubstring)
            {
                if (info.IsComplete)
                {
                    // Minimum > 0
                    string        str = info.Substring;
                    StringBuilder sb  = new StringBuilder(str);
                    for (int i = 1; i < Minimum; ++i)
                    {
                        sb.Append(str);
                    }

                    return(new AnchorInfo(this, 0, width, sb.ToString(), info.IgnoreCase));
                }

                return(new AnchorInfo(this, info.Offset, width, info.Substring, info.IgnoreCase));
            }

            return(new AnchorInfo(this, width));
        }
예제 #3
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int                fixedWidth         = 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 = (!reverse) ? base.Expressions[i] : base.Expressions[count - i - 1];
                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 (Interval item in intervalCollection)
            {
                if (item.Size > interval.Size)
                {
                    interval = item;
                }
            }
            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 = (!reverse) ? ((AnchorInfo)arrayList[k]) : ((AnchorInfo)arrayList[num2 - k - 1]);
                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");
        }