createReferenceString static method
Creates a String reference based on which fields are left null
.
Does not validate references beyond checkin to see if the book
field is left null. In cases where the book field is left null
a null
value will be returned.
Implementation
static String? createReferenceString(String? book,
[int? startChapter, int? startVerse, int? endChapter, int? endVerse]) {
if (book == null) return null;
var reference = StringBuffer(book);
if (startChapter != null) {
reference.write(' $startChapter');
if (startVerse != null) {
reference.write(':$startVerse');
if (endChapter != null && endChapter != startChapter) {
reference.write(' - $endChapter');
reference
.write(':${endVerse ?? getLastVerseNumber(endChapter) ?? 1}');
} else if (endVerse != null && endVerse != startVerse) {
reference.write('-$endVerse');
}
} else if (endChapter != null && endChapter != startChapter) {
if (endVerse != null) {
reference.write(':1 - $endChapter:$endVerse');
} else {
reference.write('-$endChapter');
}
}
}
return reference.toString();
}