mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-04 05:44:50 +00:00
Make StringLineGroup returns a count limited Enumerator
Fixes #757, before we return the array enumerator directly, enumerate it will get phantom empty lines.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
using Markdig.Helpers;
|
||||
@@ -215,4 +216,20 @@ public class TestStringSliceList
|
||||
TextAssert.AreEqual("ABC\r\nD\r\n", chars.ToString());
|
||||
TextAssert.AreEqual("ABC\r\nD", text.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestStringLineGroup_EnumeratorReturnsRealLines()
|
||||
{
|
||||
string str = "A\r\n";
|
||||
var text = new StringLineGroup(4)
|
||||
{
|
||||
new StringSlice(str, NewLine.CarriageReturnLineFeed) { Start = 0, End = 0 }
|
||||
};
|
||||
|
||||
var enumerator = ((IEnumerable)text).GetEnumerator();
|
||||
Assert.True(enumerator.MoveNext());
|
||||
StringLine currentLine = (StringLine)enumerator.Current;
|
||||
TextAssert.AreEqual("A", currentLine.ToString());
|
||||
Assert.False(enumerator.MoveNext());
|
||||
}
|
||||
}
|
||||
@@ -187,9 +187,40 @@ public struct StringLineGroup : IEnumerable
|
||||
}
|
||||
}
|
||||
|
||||
private struct Enumerator : IEnumerator
|
||||
{
|
||||
private readonly StringLineGroup _parent;
|
||||
private int _index;
|
||||
|
||||
public Enumerator(StringLineGroup parent)
|
||||
{
|
||||
_parent = parent;
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public object Current => _parent.Lines[_index];
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (++_index < _parent.Count)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return Lines.GetEnumerator();
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
private void IncreaseCapacity()
|
||||
|
||||
Reference in New Issue
Block a user