Exemplo n.º 1
0
        /// <summary>
        /// Copy a portion of source text into a target SourceText instance
        /// </summary>
        /// <param name="target"></param>
        /// <param name="from">Start offste of the portion</param>
        /// <param name="to">End offset of the portion</param>
        public override void Copy(SourceText target, int from, int to)
        {
            if (!CheckRange(length, from, to) || (target == null))
            {
                return;
            }

            if (!(target is GapSourceText))
            { // convert
                int    s   = to - from;
                char[] buf = new char[s + 1];
                CopyTo(buf, 0, from, to);
                buf[to - from] = '\0';
                target.ReplaceWithStr(buf, s);
                return;
            }

            GapSourceText ft    = (GapSourceText)target;
            int           nSize = to - from;

            ft.Empty();

            if (ft.size < nSize)
            {
                ft.Expand(nSize, 0);
            }

            CopyTo(ft.body, 0, from, to);

            ft.length = to - from;
            ft.Update(to - from);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert the content of a SourceText from a position up to a position.
        /// </summary>
        /// <param name="text">The SourceText to insert</param>
        /// <param name="from">The start location</param>
        /// <param name="to">The end location</param>
        public override void Insert(SourceText paste, int from, int to)
        {
            if (!CheckRange(length, from, to))
            {
                return;
            }

            GapSourceText ft;

            char[] buf = null;

            if (!(paste is GapSourceText))
            {  // convert the text into a GapText
                int s = paste.Size;
                buf = new char[s];
                paste.CopyInStr(buf, s, 0, s);
                ft = new GapSourceText(buf, s, true);
            }
            else
            {
                ft = (GapSourceText)paste;
            }

            int shift = ft.length - (to - from);

            if ((to - from) > 0)
            {
                Send(new TextChangeInfo(TextChanges.TextAboutDeleted, from, to));
            }

            if (HighWaterMark(shift))
            {
                Expand(GrowBy(size + shift), from);
            }
            else
            {
                MoveGap(from);
            }

            ft.CopyTo(body, from, 0, ft.length);

            length    += shift;
            gaplen    -= shift;
            part1len  += ft.length;
            part2body -= shift;
            part2len   = length - part1len;
            body2      = part2body + part1len;

            if (LowWaterMark())
            {
                Shrink();
            }
            base.Insert(paste, from, to);
            base.Send(new TextChangeInfo(TextChanges.TextReplaced, from, to, paste.Size), paste);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Save a text portion of this SourceText in another SourceText
        /// </summary>
        /// <param name="from">The start position of the portion</param>
        /// <param name="to">The end position of the portion</param>
        /// <returns>The SourceText containing the portion</returns>
        public override SourceText Save(int from, int to)
        {
            if (!CheckRange(length, from, to))
            {
                return(null);
            }

            GapSourceText t = new GapSourceText(to - from);

            Copy(t, from, to);
            return(t);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check if the given source text is equals to this one.
        /// </summary>
        /// <param name="text">The source text to be checked for equality</param>
        /// <returns>true if both the given source text is equals to this one, false otherwise</returns>
        public override bool Equals(object text)
        {
            if (!(text is GapSourceText))
            {
                return(false);
            }
            GapSourceText t = (GapSourceText)text;

            if (length != t.length)
            {
                return(false);
            }

            MoveGap(length);
            t.MoveGap(t.length);
            return(CompareArrays(body, t.body, length));
        }