2016-02-25 20:30:37 +09:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using Textamina.Markdig.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Textamina.Markdig.Syntax
|
|
|
|
|
|
{
|
|
|
|
|
|
public class StringSliceList
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly StringSlice[] Empty = new StringSlice[0];
|
|
|
|
|
|
|
|
|
|
|
|
public StringSliceList()
|
|
|
|
|
|
{
|
|
|
|
|
|
Slices = Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public StringSliceList(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (text == null) throw new ArgumentNullException(nameof(text));
|
|
|
|
|
|
Append(new StringSlice(text));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public StringSlice[] Slices;
|
|
|
|
|
|
|
|
|
|
|
|
public int Count;
|
|
|
|
|
|
|
|
|
|
|
|
public void Append(ref StringSlice slice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Count == Slices.Length) IncreaseCapacity();
|
|
|
|
|
|
Slices[Count++] = slice;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Append(StringSlice slice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Count == Slices.Length) IncreaseCapacity();
|
|
|
|
|
|
Slices[Count++] = slice;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void IncreaseCapacity()
|
|
|
|
|
|
{
|
|
|
|
|
|
int newCapacity = Slices.Length == 0 ? 4 : Slices.Length * 2;
|
|
|
|
|
|
var newItems = new StringSlice[newCapacity];
|
|
|
|
|
|
if (Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(Slices, 0, newItems, 0, Count);
|
|
|
|
|
|
}
|
|
|
|
|
|
Slices = newItems;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2016-02-26 07:35:49 +09:00
|
|
|
|
return ToString(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ToString(bool replaceEndOfLineBySpace)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newLine = replaceEndOfLineBySpace ? ' ' : '\n';
|
2016-02-25 22:10:52 +09:00
|
|
|
|
var builder = StringBuilderCache.Local();
|
2016-02-26 07:35:49 +09:00
|
|
|
|
for (int i = 0; i < Count; i++)
|
2016-02-25 20:30:37 +09:00
|
|
|
|
{
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
|
{
|
2016-02-26 07:35:49 +09:00
|
|
|
|
builder.Append(newLine);
|
2016-02-25 20:30:37 +09:00
|
|
|
|
}
|
2016-02-25 22:10:52 +09:00
|
|
|
|
builder.Append(Slices[i].Text, Slices[i].Start, Slices[i].Length);
|
2016-02-25 20:30:37 +09:00
|
|
|
|
}
|
2016-02-25 22:10:52 +09:00
|
|
|
|
var str = builder.ToString();
|
|
|
|
|
|
builder.Clear();
|
2016-02-25 20:30:37 +09:00
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|