src/Markdig/Helpers/StringLineGroup.cs
/// <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>
Converts the lines to a single  by concatenating the lines.
Converts the lines to a single by concatenating the lines .
public readonly StringSlice ToSlice(List<LineOffset>? lineOffsets = null)
        {
            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];
            }
            if (Count == 0)
            {
                return StringSlice.Empty;
            }
            if (lineOffsets != null && lineOffsets.Capacity < lineOffsets.Count + Count)
            {
                lineOffsets.Capacity = Math.Max(lineOffsets.Count + Count, lineOffsets.Capacity * 2);
            }
            var builder = StringBuilderCache.Local();
            int previousStartOfLine = 0;
            var newLine = NewLine.None;
            for (int i = 0; i < Count; i++)
            {
                if (i > 0)
                {
                    builder.Append(newLine.AsString());
                    previousStartOfLine = builder.Length;
                }
                ref StringLine line = ref Lines[i];
                if (!line.Slice.IsEmpty)
                {
                    builder.Append(line.Slice.Text, line.Slice.Start, line.Slice.Length);
                }
                newLine = line.NewLine;
                lineOffsets?.Add(new LineOffset(line.Position, line.Column, line.Slice.Start - line.Position, previousStartOfLine, builder.Length));
            }
            return new StringSlice(builder.GetStringAndReset());
        }
public readonly StringSlice ToSlice ( List < LineOffset > ? lineOffsets = null ) { 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 ] ; } if ( Count == 0 ) { return StringSlice . Empty ; } if ( lineOffsets != null && lineOffsets . Capacity < lineOffsets . Count + Count ) { lineOffsets . Capacity = Math . Max ( lineOffsets . Count + Count , lineOffsets . Capacity * 2 ) ; } var builder = StringBuilderCache . Local ( ) ; int previousStartOfLine = 0 ; var newLine = NewLine . None ; for ( int i = 0 ; i < Count ; i ++ ) { if ( i > 0 ) { builder . Append ( newLine . AsString ( ) ) ; previousStartOfLine = builder . Length ; } ref StringLine line = ref Lines [ i ] ; if ( ! line . Slice . IsEmpty ) { builder . Append ( line . Slice . Text , line . Slice . Start , line . Slice . Length ) ; } newLine = line . NewLine ; lineOffsets ? . Add ( new LineOffset ( line . Position , line . Column , line . Slice . Start - line . Position , previousStartOfLine , builder . Length ) ) ; } return new StringSlice ( builder . GetStringAndReset ( ) ) ; }
Converts the lines to a single  by concatenating the lines.
Converts the lines to a single by concatenating the lines .
// Optimization case for a single line. // Optimization case when no lines // Else use a builder
A single slice concatenating the lines of this instance
A single slice concatenating the lines of this instance
lineOffsets
List<LineOffset>?
The position of the `\n` line offsets from the beginning of the returned slice.
The position of the ` \ n ` line offsets from the beginning of the returned slice .