Exemplo n.º 1
0
        public void AddOffset(int position, int offset)
        {
            if (offset == 0)
            {
                return;
            }

            if (OffsetCount == Offsets.Length)
            {
                Array.Resize(ref Offsets, OffsetCount + 20);
            }

            Offsets[OffsetCount++] = new PositionOffset(position, offset);
        }
Exemplo n.º 2
0
        public void AddOffset(LineInfo line, int startIndex, int length)
        {
            if (OffsetCount + line.OffsetCount + 2 >= Offsets.Length)
            {
                Array.Resize(ref Offsets, Offsets.Length + line.OffsetCount + 20);
            }

            PositionOffset po1, po2;

            if (startIndex > 0)
            {
                po1 = new PositionOffset(
                    CalculateOrigin(line.Offsets, line.OffsetCount, line.LineOffset, false, true),
                    startIndex);
            }
            else
            {
                po1 = EmptyPositionOffset;
            }

            if (line.Line.Length - startIndex - length > 0)
            {
                po2 = new PositionOffset(
                    CalculateOrigin(line.Offsets, line.OffsetCount, line.LineOffset + startIndex + length, false, true),
                    line.Line.Length - startIndex - length);
            }
            else
            {
                po2 = EmptyPositionOffset;
            }

            var indexAfterLastCopied = 0;

            if (po1.Offset == 0)
            {
                if (po2.Offset == 0)
                {
                    goto FINTOTAL;
                }

                po1 = po2;
                po2 = EmptyPositionOffset;
            }

            for (var i = 0; i < line.OffsetCount; i++)
            {
                var pc = line.Offsets[i];
                if (pc.Position > po1.Position)
                {
                    if (i > indexAfterLastCopied)
                    {
                        Array.Copy(line.Offsets, indexAfterLastCopied, Offsets, OffsetCount, i - indexAfterLastCopied);
                        OffsetCount         += i - indexAfterLastCopied;
                        indexAfterLastCopied = i;
                    }

                    Offsets[OffsetCount++] = po1;

                    po1 = po2;

                    if (po1.Offset == 0)
                    {
                        goto FIN;
                    }

                    po2 = EmptyPositionOffset;
                }
            }

FIN:
            if (po1.Offset != 0)
            {
                Offsets[OffsetCount++] = po1;
            }

            if (po2.Offset != 0)
            {
                Offsets[OffsetCount++] = po2;
            }

FINTOTAL:
            Array.Copy(line.Offsets, indexAfterLastCopied, Offsets, OffsetCount, line.OffsetCount - indexAfterLastCopied);
            OffsetCount += line.OffsetCount - indexAfterLastCopied;
        }