Skip to content

Commit

Permalink
rs/fix unknown markers (#138)
Browse files Browse the repository at this point in the history
* Improve the functionality of IgnoreUnknown

* Fix tests
  • Loading branch information
rbnswartz authored Jan 18, 2024
1 parent 7d9c11f commit dbdef85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
15 changes: 13 additions & 2 deletions USFMToolsSharp/USFMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ private List<Marker> TokenizeFromString(string input)
ConvertToMarkerResult result = ConvertToMarker(match.Groups[1].Value, match.Groups[2].Value);
result.marker.Position = match.Index;

// If this is an unkown marker and we're in Ignore Unkown Marker mode then don't add the marker. We still keep any remaining text though
if (!(result.marker is UnknownMarker) || !IgnoreUnknownMarkers)
// If this is an unknown marker and we're in Ignore Unknown Marker mode then don't add the marker. We still keep any remaining text though
if (result.marker is UnknownMarker unknownMarker)
{
if (IgnoreUnknownMarkers)
{
output.Add(new TextBlock(unknownMarker.ParsedValue));
}
else
{
output.Add(result.marker);
}
}
else
{
output.Add(result.marker);
}
Expand Down
2 changes: 1 addition & 1 deletion USFMToolsSharp/USFMToolsSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RepositoryUrl>https://github.com/WycliffeAssociates/USFMToolsSharp</RepositoryUrl>
<Copyright />
<PackageLicenseUrl></PackageLicenseUrl>
<Version>1.9.0</Version>
<Version>1.10.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>Wycliffe Associates</Company>
<Authors>@rbnswartz</Authors>
Expand Down
9 changes: 4 additions & 5 deletions USFMToolsSharpTest/USFMParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ public void TestFigureParse()
{
//PRE 3.0 TESTS
//Description;
Assert.AreEqual("description", ((FIGMarker)parser.ParseFromString
("\\fig description|filepath|width|location|copyright|caption caption caption|reference\\fig*").Contents[0]).Description);
Assert.AreEqual("description", ((FIGMarker)parser.ParseFromString("\\fig description|filepath|width|location|copyright|caption caption caption|reference\\fig*").Contents[0]).Description);
//FilePath;
Assert.AreEqual("filepath", ((FIGMarker)parser.ParseFromString
("\\fig description| filepath|width|location|copyright|caption caption caption|reference\\fig*").Contents[0]).FilePath);
Expand Down Expand Up @@ -680,12 +679,12 @@ public void TestSpacingBetweenWords()
Assert.AreEqual(" ", ((TextBlock)parsed.Contents[0].Contents[3]).Text);
}
[TestMethod]
public void TestIgnoreUnkownMarkers()
public void TestIgnoreUnknownMarkers()
{
parser = new USFMParser(ignoreUnknownMarkers: true);
var parsed = parser.ParseFromString("\\v 1 Text \\unkown more text \\bd Text \\bd*");
var parsed = parser.ParseFromString("\\v 1 Text \\unknown more text \\bd Text \\bd*");
Assert.AreEqual(1, parsed.Contents.Count);
Assert.AreEqual(3, parsed.Contents[0].Contents.Count);
Assert.AreEqual(4, parsed.Contents[0].Contents.Count);
}

[TestMethod]
Expand Down

0 comments on commit dbdef85

Please sign in to comment.