Пример #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(next, from, to) || target == null)
            {
                return;
            }

            if (!(target is StringSourceText))
            { // convert
                int    s   = to - from;
                char[] buf = new char[s];
                Array.Copy(content, from, buf, 0, s);
                target.ReplaceWithStr(buf, s);
                return;
            }

            StringSourceText ct = (StringSourceText)target;
            int nSave           = to - from;

            if (ct.size < nSave)
            {
                ct.Expand(nSave);
            }

            Array.Copy(content, from, ct.content, 0, nSave);
            ct.next = nSave;
        }
Пример #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)
        {
            StringSourceText ct;

            char[] buf = null;

            if (!(paste is StringSourceText))
            { // try to convert
                int s = paste.Size;
                buf = new char[s];
                paste.CopyInStr(buf, s, 0, s);
                ct = new StringSourceText(buf, s);
            }
            else
            {
                ct = (StringSourceText)paste;
            }

            int shift = ct.next - (to - from);

            if (!CheckRange(next, from, to))
            {
                return;
            }

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

            if (HighWaterMark(shift))
            {
                Expand(GrowBy(size + shift));
            }

            if (shift < 0)
            {
                Array.Copy(content, to, content, to + shift, next - to);
            }
            else if (shift > 0)
            {
                Array.Copy(content, from, content, from + shift, next - from);
            }

            //---- insert pasted text
            Array.Copy(ct.content, 0, content, from, ct.next);
            next += shift;
            if (LowWaterMark())
            {
                Expand(size / 2);
            }
            base.Insert(paste, from, to);
            Send(new TextChangeInfo(TextChanges.TextReplaced, from, to, paste.Size), paste);
        }
Пример #3
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 obj)
        {
            if (!(obj is StringSourceText))
            {
                return(false);
            }
            StringSourceText t = (StringSourceText)obj;

            if (next != t.next)
            {
                return(false);
            }
            return(CompareArrays(content, t.content, next));
        }