From 4cf9da363ea6601e3d537b78306839b0b6c2bb19 Mon Sep 17 00:00:00 2001 From: Bryan Ho Date: Wed, 14 Aug 2019 18:47:54 -0400 Subject: [PATCH] Support Unordered Chapters --- .../LinterModules/UnorderedChapters.cs | 44 +++++++++++++++++++ USFMToolsSharp.Linter/USFMLinter.cs | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs diff --git a/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs b/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs new file mode 100644 index 0000000..160a7d3 --- /dev/null +++ b/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using USFMToolsSharp.Linter.LinterModules; +using USFMToolsSharp.Linter.Models; +using USFMToolsSharp.Models.Markers; + +namespace USFMToolsSharp.Linter.LinterModules +{ + public class UnorderedChapters : ILinterModule + { + public List Lint(USFMDocument input) + { + List chapterIndecies = new List(); + List results = new List(); + foreach (Marker marker in input.Contents) + { + if (marker is CMarker) + { + int chapIndex = ((CMarker)marker).Number; + if (chapterIndecies.Count != 0) + { + if (chapIndex != chapterIndecies[chapterIndecies.Count - 1] + 1) + { + results.Add(new LinterResult + { + Position = marker.Position, + Level = LinterLevel.Error, + Message = $"Chapter {chapIndex} is not in the correct order." + }); + } + } + + chapterIndecies.Add(((CMarker)marker).Number); + } + if (marker is IDMarker) + { + chapterIndecies.Clear(); + } + } + return results; + } + } +} \ No newline at end of file diff --git a/USFMToolsSharp.Linter/USFMLinter.cs b/USFMToolsSharp.Linter/USFMLinter.cs index 0a2e3b6..a7326e7 100644 --- a/USFMToolsSharp.Linter/USFMLinter.cs +++ b/USFMToolsSharp.Linter/USFMLinter.cs @@ -14,7 +14,8 @@ public class USFMLinter new VerseMarkerValidation(), new MissingEndMarkers(), new UnpairedEndMarkers(), - new MissingTableRows() + new MissingTableRows(), + new UnorderedChapters() }; public List Lint(USFMDocument input) {