示例#1
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Inserts text into the text block array.  The text is either a string
        // or an array of char.
        internal static void InsertText(TextTreeRootTextBlock rootTextBlock, int offset, object text)
        {
            TextTreeTextBlock block;
            int localOffset;
            int insertCount;
            int textLength;

            Invariant.Assert(text is string || text is char[], "Bad text parameter!");

            // Get the block matching the insertion point.
            block = FindBlock(rootTextBlock, offset, out localOffset);

            // Fill this block to capacity.
            textLength  = TextContainer.GetTextLength(text);
            insertCount = block.InsertText(localOffset, text, 0, textLength);

            if (insertCount < textLength)
            {
                // Put all the text to the smaller side of the gap into the new block.
                if (block.GapOffset < TextTreeTextBlock.MaxBlockSize / 2)
                {
                    InsertTextLeft(block, text, insertCount);
                }
                else
                {
                    InsertTextRight(block, text, insertCount);
                }
            }
        }
示例#2
0
        // Helper for InsertText.  Inserts text to the right of an existing block.
        private static void InsertTextRight(TextTreeTextBlock leftBlock, object text, int textOffset)
        {
            int newBlockCount;
            TextTreeTextBlock rightBlock;
            TextTreeTextBlock neighborBlock;
            TextTreeTextBlock newBlock;
            int count;
            int textEndOffset;
            int i;

            textEndOffset = TextContainer.GetTextLength(text);

            if (leftBlock.GapOffset == leftBlock.Count)
            {
                // Try to fill neighbor block.
                neighborBlock = (TextTreeTextBlock)leftBlock.GetNextNode();
                if (neighborBlock != null)
                {
                    count = Math.Min(neighborBlock.FreeCapacity, textEndOffset - textOffset);
                    neighborBlock.InsertText(0, text, textEndOffset - count, textEndOffset);
                    textEndOffset -= count;
                }
            }

            if (textOffset < textEndOffset)
            {
                // Try adding just one block.
                newBlockCount = 1;

                rightBlock = leftBlock.SplitBlock();

                // Fill up the right block.
                count = Math.Min(rightBlock.FreeCapacity, textEndOffset - textOffset);
                rightBlock.InsertText(0, text, textEndOffset - count, textEndOffset);
                textEndOffset -= count;

                if (textOffset < textEndOffset)
                {
                    // Fill up the larger block.
                    // We need to copy from the end of the text here.
                    textOffset += leftBlock.InsertText(leftBlock.Count, text, textOffset, textEndOffset);

                    if (textOffset < textEndOffset)
                    {
                        // We've filled both blocks, and there's still more text to copy.
                        // Prepare to allocate some more blocks.
                        newBlockCount += (textEndOffset - textOffset + TextTreeTextBlock.MaxBlockSize - 1) / TextTreeTextBlock.MaxBlockSize;
                    }
                }

                for (i = 0; i < newBlockCount - 1; i++)
                {
                    newBlock    = new TextTreeTextBlock(TextTreeTextBlock.MaxBlockSize);
                    textOffset += newBlock.InsertText(0, text, textOffset, textEndOffset);
                    newBlock.InsertAtNode(leftBlock, false /* insertBefore */);
                    leftBlock = newBlock;
                }
                Invariant.Assert(textOffset == textEndOffset, "Not all text copied!");
            }
        }
示例#3
0
        // Token: 0x06003DA6 RID: 15782 RVA: 0x0011C460 File Offset: 0x0011A660
        internal static void InsertText(TextTreeRootTextBlock rootTextBlock, int offset, object text)
        {
            Invariant.Assert(text is string || text is char[], "Bad text parameter!");
            int logicalOffset;
            TextTreeTextBlock textTreeTextBlock = TextTreeText.FindBlock(rootTextBlock, offset, out logicalOffset);
            int textLength = TextContainer.GetTextLength(text);
            int num        = textTreeTextBlock.InsertText(logicalOffset, text, 0, textLength);

            if (num < textLength)
            {
                if (textTreeTextBlock.GapOffset < 2048)
                {
                    TextTreeText.InsertTextLeft(textTreeTextBlock, text, num);
                    return;
                }
                TextTreeText.InsertTextRight(textTreeTextBlock, text, num);
            }
        }
示例#4
0
        // Token: 0x06003DAF RID: 15791 RVA: 0x0011C7F8 File Offset: 0x0011A9F8
        private static void InsertTextRight(TextTreeTextBlock leftBlock, object text, int textOffset)
        {
            int num = TextContainer.GetTextLength(text);

            if (leftBlock.GapOffset == leftBlock.Count)
            {
                TextTreeTextBlock textTreeTextBlock = (TextTreeTextBlock)leftBlock.GetNextNode();
                if (textTreeTextBlock != null)
                {
                    int num2 = Math.Min(textTreeTextBlock.FreeCapacity, num - textOffset);
                    textTreeTextBlock.InsertText(0, text, num - num2, num);
                    num -= num2;
                }
            }
            if (textOffset < num)
            {
                int num3 = 1;
                TextTreeTextBlock textTreeTextBlock2 = leftBlock.SplitBlock();
                int num2 = Math.Min(textTreeTextBlock2.FreeCapacity, num - textOffset);
                textTreeTextBlock2.InsertText(0, text, num - num2, num);
                num -= num2;
                if (textOffset < num)
                {
                    textOffset += leftBlock.InsertText(leftBlock.Count, text, textOffset, num);
                    if (textOffset < num)
                    {
                        num3 += (num - textOffset + 4096 - 1) / 4096;
                    }
                }
                for (int i = 0; i < num3 - 1; i++)
                {
                    TextTreeTextBlock textTreeTextBlock3 = new TextTreeTextBlock(4096);
                    textOffset += textTreeTextBlock3.InsertText(0, text, textOffset, num);
                    textTreeTextBlock3.InsertAtNode(leftBlock, false);
                    leftBlock = textTreeTextBlock3;
                }
                Invariant.Assert(textOffset == num, "Not all text copied!");
            }
        }
示例#5
0
        // Token: 0x06003DAE RID: 15790 RVA: 0x0011C700 File Offset: 0x0011A900
        private static void InsertTextLeft(TextTreeTextBlock rightBlock, object text, int textOffset)
        {
            int num        = -1;
            int textLength = TextContainer.GetTextLength(text);

            if (rightBlock.GapOffset == 0)
            {
                TextTreeTextBlock textTreeTextBlock = (TextTreeTextBlock)rightBlock.GetPreviousNode();
                if (textTreeTextBlock != null)
                {
                    textOffset += textTreeTextBlock.InsertText(textTreeTextBlock.Count, text, textOffset, textLength);
                }
            }
            if (textOffset < textLength)
            {
                int num2 = 1;
                TextTreeTextBlock textTreeTextBlock2 = rightBlock.SplitBlock();
                textOffset += textTreeTextBlock2.InsertText(textTreeTextBlock2.Count, text, textOffset, textLength);
                if (textOffset < textLength)
                {
                    int num3 = Math.Min(rightBlock.FreeCapacity, textLength - textOffset);
                    num = textLength - num3;
                    rightBlock.InsertText(0, text, num, textLength);
                    if (textOffset < num)
                    {
                        num2 += (num - textOffset + 4096 - 1) / 4096;
                    }
                }
                for (int i = 1; i < num2; i++)
                {
                    TextTreeTextBlock textTreeTextBlock3 = new TextTreeTextBlock(4096);
                    textOffset += textTreeTextBlock3.InsertText(0, text, textOffset, num);
                    textTreeTextBlock3.InsertAtNode(textTreeTextBlock2, false);
                    textTreeTextBlock2 = textTreeTextBlock3;
                }
                Invariant.Assert(num2 == 1 || textOffset == num, "Not all text copied!");
            }
        }