Skip to content

Commit

Permalink
Ignore freestanding ellipses
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Aug 23, 2024
1 parent 1220953 commit 7f02609
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public override void EndNote(UsfmParserState state, string marker, bool closed)
public override void Text(UsfmParserState state, string text)
{
// if we hit text in a verse paragraph and we aren't in a verse, then start a non-verse segment
if (text.Trim().Length > 0)
if (text.Trim().Length > 0 && text.Trim() != "...")
CheckConvertVerseParaToNonVerse(state);
}

Expand Down
5 changes: 5 additions & 0 deletions src/SIL.Machine/Corpora/UsfmTextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public override void Text(UsfmParserState state, string text)
if (_rowTexts.Count == 0)
return;

if (text.Trim() == "...")
{
text = "";
}

StringBuilder rowText = _rowTexts.Peek();
if (_text._includeMarkers)
{
Expand Down
41 changes: 41 additions & 0 deletions tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,47 @@ public void GetRows_OptBreak_BeginningIncludeMarkers()
});
}

[Test]
public void GetRows_IgnoreLoneEllipsis()
{
TextRow[] rows = GetRows(
@"\id MAT - Test
\c 1
\q1
\f \fr 119 \ft World \f*
\v 1 ...
\v 2 Text
\c 2
\d
description
\b
",
includeAllText: true
);
Assert.Multiple(() =>
{
Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.Select(tr => tr.Text)));
Assert.That(rows[1].Text, Is.EqualTo(""));
});
}

[Test]
public void GetRows_Ellipsis()
{
TextRow[] rows = GetRows(
@"\id MAT - Test
\c 1
\v 1 Verse text ... More text
",
includeAllText: true
);
Assert.Multiple(() =>
{
Assert.That(rows, Has.Length.EqualTo(1), string.Join(",", rows.Select(tr => tr.Text)));
Assert.That(rows[0].Text, Is.EqualTo("Verse text ... More text"));
});
}

private static TextRow[] GetRows(string usfm, bool includeMarkers = false, bool includeAllText = false)
{
UsfmMemoryText text =
Expand Down

0 comments on commit 7f02609

Please sign in to comment.