Skip to content

Commit 611b978

Browse files
authored
Add TryParse to ScriptureRef (#357)
1 parent c5e7c02 commit 611b978

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/SIL.Machine/Corpora/ScriptureRef.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ public static ScriptureRef Parse(string str, ScrVers versification = null)
4343
return new ScriptureRef(new VerseRef(vref, versification ?? ScrVers.English), path);
4444
}
4545

46+
public static bool TryParse(string str, out ScriptureRef scriptureRef)
47+
{
48+
return TryParse(str, null, out scriptureRef);
49+
}
50+
51+
public static bool TryParse(string str, ScrVers versification, out ScriptureRef scriptureRef)
52+
{
53+
try
54+
{
55+
scriptureRef = Parse(str, versification);
56+
return true;
57+
}
58+
catch (VerseRefException)
59+
{
60+
scriptureRef = Empty;
61+
return false;
62+
}
63+
}
64+
4665
public ScriptureRef(VerseRef verseRef = default, IEnumerable<ScriptureElement> path = null)
4766
{
4867
VerseRef = verseRef;

0 commit comments

Comments
 (0)