Exemplo n.º 1
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!");
            }
        }
Exemplo n.º 2
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!");
            }
        }
Exemplo n.º 3
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!");
            }
        }
Exemplo n.º 4
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!");
            }
        }