sillsdev / sillsdev/machine

Add a TryGetChapters function to ScriptureRangeParser

Open
#486 0 comments 0 reactions 1 assignee View on GitHub

@pmachapman is already working on this.

Since Sep 14, 2026.

Dominant language
C#
Stars
29
Forks
17
Avg merge
3d 2h
Merged PRs (30d)
8

Description

When I call ScriptureRangeParser.GetChapters(), I sometimes need to wrap it in a try/catch to ensure that any invalid chapter ranges (i.e. because a versification has changed) do not crash the method calling it, and I would rather the method just skip the range.

Does it make sense to have a ScriptureRangeParser.TryGetChapters(string scriptureRange, out Dictionary<string, List<int>> chapters) method that returns true if the chapters were retrieved, or false if they were not?

Another option could be to have a more forgiving GetChapters() implementation that will just parse the chapter ranges specified, even if they are not precisely the same as the versification requires (i.e. additional chapter numbers are in the range)

In Scripture Forge I created an extension method along the lines of:

    public static bool TryGetChapters(
        this ScriptureRangeParser scriptureRangeParser,
        string chapterSelections,
        [NotNullWhen(true)] out Dictionary<string, List<int>>? chapters
    )
    {
        try
        {
            chapters = scriptureRangeParser.GetChapters(chapterSelections);
            return true;
        }
        catch (ArgumentException)
        {
            chapters = null;
            return false;
        }
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.