referenceFromOsisIdentifier function
Parses a verse or full-endpoint range OSIS identifier.
Supported shapes are John.3.16 and
2Cor.6.14-2Cor.7.1. The syntax and book identifiers are
case-sensitive. Throws FormatException for malformed input, unknown book
identifiers, invalid coordinates, or non-ascending ranges.
A verse may have a single lowercase subdivision after !, as in
John.1.5!a or John.1.5!a-John.1.5!b. Other OSIS sub-identifiers are
outside this package's verse model and are rejected.
Implementation
Reference referenceFromOsisIdentifier(String identifier) {
final match = _osisReferencePattern.firstMatch(identifier);
if (match == null) {
throw FormatException(
'Invalid OSIS reference identifier; expected BOOK.CHAPTER.VERSE or '
'BOOK.CHAPTER.VERSE-BOOK.CHAPTER.VERSE',
identifier,
);
}
final start = _parseVerseEndpoint(
identifier,
formatName: 'OSIS',
bookIdentifier: match[1]!,
chapterToken: match[2]!,
verseToken: match[3]!,
subdivision: match[4],
bookLookup: bibleBookFromOsisIdentifier,
);
if (match[5] == null) return start;
final end = _parseVerseEndpoint(
identifier,
formatName: 'OSIS',
bookIdentifier: match[5]!,
chapterToken: match[6]!,
verseToken: match[7]!,
subdivision: match[8],
bookLookup: bibleBookFromOsisIdentifier,
);
return _checkedRange(start, end, identifier, formatName: 'OSIS');
}