// Constructor // Methods public void Add(Verse verse) { if (verse == null) throw new ArgumentNullException("verse"); _data.Add(verse); }
private void ProcessVerse(String line) { // Assertion if (_curBook == null) throw VerseException("There is no current book."); // Parse the chapter & verse reference int colonPos = line.IndexOf(':'); int spacePos = line.IndexOf(' '); if (colonPos < 0 || spacePos < 0) throw VerseException("Invalid chapter or verse format. (1)"); int chap = Int32.Parse(line.Substring(0, colonPos)); int verse = Int32.Parse(line.Substring(colonPos + 1, spacePos - colonPos - 1)); if (chap <= 0 || verse <= 0) throw VerseException("Invalid chapter or verse format. (2)"); // Parse out the verse info String verseData = line.Substring(spacePos + 1); // Get the current chapter object if (_curChapter == null) { if (chap != 1 || verse != 1) throw VerseException("Expected first verse and chapter of the book."); SetupNewCurrentChapter(chap - 1); } else { if (_curChapter.ChapterNum != chap - 1) { if (verse != 1) throw VerseException("Expected first verse of the chapter."); if (_curChapter.ChapterNum + 1 != chap - 1) throw VerseException("The chapter number was incremented by more than one."); SetupNewCurrentChapter(chap - 1); } } if (_preAccum != null) throw VerseException("Unexpected preface data."); // Append a new verse object var verseObj = new Verse(_bible.GetNextVerseId(), verse - 1, verseData, _curChapter); if (_curChapter == null) throw new InvalidOperationException("No valid chapter."); _curChapter.Verses.Add(verseObj); }