Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public override AnchorInfo GetAnchorInfo(bool reverse)
        {
            int fixedWidth = base.GetFixedWidth();

            if (this.Minimum == 0)
            {
                return(new AnchorInfo(this, fixedWidth));
            }
            AnchorInfo anchorInfo = this.Expression.GetAnchorInfo(reverse);

            if (anchorInfo.IsPosition)
            {
                return(new AnchorInfo(this, anchorInfo.Offset, fixedWidth, anchorInfo.Position));
            }
            if (!anchorInfo.IsSubstring)
            {
                return(new AnchorInfo(this, fixedWidth));
            }
            if (anchorInfo.IsComplete)
            {
                string        substring     = anchorInfo.Substring;
                StringBuilder stringBuilder = new StringBuilder(substring);
                for (int i = 1; i < this.Minimum; i++)
                {
                    stringBuilder.Append(substring);
                }
                return(new AnchorInfo(this, 0, fixedWidth, stringBuilder.ToString(), anchorInfo.IgnoreCase));
            }
            return(new AnchorInfo(this, anchorInfo.Offset, fixedWidth, anchorInfo.Substring, anchorInfo.IgnoreCase));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            // info block

            int min, max;

            GetWidth(out min, out max);
            cmp.EmitInfo(group_count, min, max);

            // anchoring expression

            AnchorInfo info = GetAnchorInfo(reverse);
            //if (reverse)
            //	info = new AnchorInfo (this, GetFixedWidth ());	// FIXME

            LinkRef pattern = cmp.NewLink();

            cmp.EmitAnchor(reverse, info.Offset, pattern);

            if (info.IsPosition)
            {
                cmp.EmitPosition(info.Position);
            }
            else if (info.IsSubstring)
            {
                cmp.EmitString(info.Substring, info.IgnoreCase, reverse);
            }

            cmp.EmitTrue();

            // pattern

            cmp.ResolveLink(pattern);
            base.Compile(cmp, reverse);
            cmp.EmitTrue();
        }
Ejemplo n.º 5
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            int min;
            int max;

            this.GetWidth(out min, out max);
            cmp.EmitInfo(this.group_count, min, max);
            AnchorInfo anchorInfo = this.GetAnchorInfo(reverse);
            LinkRef    linkRef    = cmp.NewLink();

            cmp.EmitAnchor(reverse, anchorInfo.Offset, linkRef);
            if (anchorInfo.IsPosition)
            {
                cmp.EmitPosition(anchorInfo.Position);
            }
            else if (anchorInfo.IsSubstring)
            {
                cmp.EmitString(anchorInfo.Substring, anchorInfo.IgnoreCase, reverse);
            }
            cmp.EmitTrue();
            cmp.ResolveLink(linkRef);
            base.Compile(cmp, reverse);
            cmp.EmitTrue();
        }
Ejemplo n.º 6
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.º 7
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.º 8
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");
        }