示例#1
0
        /// <summary>
        /// Inserts the specified <see cref="Strip"/> behind target strip
        /// at given offset.
        /// </summary>
        /// <param name="inserted">The inserted strip.</param>
        /// <param name="target">The target strip.</param>
        /// <param name="offset">The offset in target strip where data will be placed.</param>
        private void insert(Strip inserted, Strip target, int offset)
        {
            target.Split(offset);

            inserted.Next = target.Next;
            target.Next   = inserted;
        }
示例#2
0
        /// <summary>
        /// Writes data at the specified offset.
        /// </summary>
        /// <param name="offset">The offset where data will be written.</param>
        /// <param name="data">The data that will be written.</param>
        public void Write(int offset, string data)
        {
            var strip  = getStrip(offset);
            var nStrip = new Strip(data);

            insert(nStrip, strip, offset);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Strip"/> class.
        /// </summary>
        /// <param name="toClone">To clone.</param>
        internal Strip(Strip toClone)
        {
            Data           = toClone.Data;
            StartingOffset = toClone.StartingOffset;
            IsOriginal     = toClone.IsOriginal;

            if (toClone.Next != null)
            {
                Next = new Strip(toClone.Next);
            }
        }
示例#4
0
        /// <summary>
        /// Get strip containing given offset.
        /// </summary>
        /// <param name="offset">Searched offset.</param>
        /// <param name="startStrip">The start strip.</param>
        /// <returns>Strip containing given offset.</returns>
        private Strip getStrip(int offset, Strip startStrip = null)
        {
            if (startStrip == null)
            {
                startStrip = _root;
            }

            while (startStrip != null)
            {
                if (startStrip.Contains(offset))
                {
                    return(startStrip);
                }

                startStrip = startStrip.Next;
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Splits the specified offset.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <exception cref="System.NotSupportedException">Cannot split according to not contained offset</exception>
        internal void Split(int offset)
        {
            if (!Contains(offset))
            {
                throw new NotSupportedException("Cannot split according to not contained offset");
            }

            if (offset == EndingOffset)
            {
                //there is no need to split strip
                return;
            }

            var splitLine = offset - StartingOffset;
            var part1     = Data.Substring(0, splitLine);
            var part2     = Data.Substring(splitLine);

            Data = part1;

            var strip = new Strip(part2, offset);

            strip.Next = this.Next;
            this.Next  = strip;
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StripManager" /> class
 /// from given strip manager, which data will be cloned.
 /// </summary>
 /// <param name="toClone">The manager that will be cloned.</param>
 public StripManager(StripManager toClone)
 {
     _root = new Strip(toClone._root);
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StripManager" /> class
 /// from given source code data.
 /// </summary>
 /// <param name="data">The source code.</param>
 public StripManager(string data)
 {
     _root = new Strip(data, 0);
 }