Exemple #1
0
 public void Add(StringSlice slice)
 {
     if (Count == Lines.Length)
     {
         IncreaseCapacity();
     }
     Lines[Count++] = new StringLine(ref slice);
 }
Exemple #2
0
 public void Add(ref StringLine line)
 {
     if (Count == Lines.Length)
     {
         IncreaseCapacity();
     }
     Lines[Count++] = line;
 }
Exemple #3
0
 /// <summary>
 /// Converts the lines to a single <see cref="StringSlice"/> by concatenating the lines.
 /// </summary>
 /// <param name="lineOffsets">The position of the `\n` line offsets from the beginning of the returned slice.</param>
 /// <returns>A single slice concatenating the lines of this instance</returns>
 public readonly StringSlice ToSlice(List <LineOffset>?lineOffsets = null)
 {
     // Optimization case for a single line.
     if (Count == 1)
     {
         ref StringLine line = ref Lines[0];
         lineOffsets?.Add(new LineOffset(line.Position, line.Column, line.Slice.Start - line.Position, line.Slice.Start, line.Slice.End + 1));
         return(Lines[0]);
     }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringLineGroup"/> class.
 /// </summary>
 /// <param name="capacity"></param>
 public StringLineGroup(int capacity)
 {
     if (capacity <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(capacity));
     }
     Lines = new StringLine[capacity];
     Count = 0;
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringLineGroup"/> class.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public StringLineGroup(string text)
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     Lines = new StringLine[1];
     Count = 0;
     Add(new StringSlice(text));
 }
        /// <summary>
        /// Removes the line at the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        public void RemoveAt(int index)
        {
            if (index != Count - 1)
            {
                Array.Copy(Lines, index + 1, Lines, index, Count - index - 1);
            }

            Lines[Count - 1] = new StringLine();
            Count--;
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringLineGroup"/> class.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <exception cref="ArgumentNullException"></exception>
 public StringLineGroup(string text)
 {
     if (text == null)
     {
         ThrowHelper.ArgumentNullException_text();
     }
     Lines = new StringLine[1];
     Count = 0;
     Add(new StringSlice(text));
 }
Exemple #8
0
        private void IncreaseCapacity()
        {
            var newItems = new StringLine[Lines.Length * 2];

            if (Count > 0)
            {
                Array.Copy(Lines, 0, newItems, 0, Count);
            }
            Lines = newItems;
        }
Exemple #9
0
 /// <summary>
 /// Removes the line at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 public void RemoveAt(int index)
 {
     if (Count - 1 == index)
     {
         Count--;
     }
     else
     {
         Array.Copy(Lines, index + 1, Lines, index, Count - index - 1);
         Lines[Count - 1] = new StringLine();
         Count--;
     }
 }