/// ----------------------------------------------------------------------------------- ///<summary> /// Verify the specified ScrVerse ///</summary> ///<param name="verse">specified ScrVerse</param> ///<param name="cache">database</param> ///<param name="verseText">expected text within the ScrVerse</param> ///<param name="styleName">expected stylename for the ScrVerse paragraph</param> ///<param name="startRef">expected starting reference</param> ///<param name="endRef">expected ending reference</param> /// ----------------------------------------------------------------------------------- public static void VerifyScrVerse(ScrVerse verse, FdoCache cache, string verseText, string styleName, BCVRef startRef, BCVRef endRef) { ScrTxtPara versePara = new ScrTxtPara(cache, verse.HvoPara); if (string.IsNullOrEmpty(verseText)) { Assert.IsTrue(verse.Text == null || string.IsNullOrEmpty(verse.Text.Text)); } else { Assert.AreEqual(verseText, verse.Text.Text); } Assert.AreEqual(styleName, ScrStyleNames.GetStyleName(versePara.Hvo, cache)); Assert.AreEqual(startRef, verse.StartRef); Assert.AreEqual(endRef, verse.EndRef); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Advances the enumerator to the next verse in the paragraph. /// </summary> /// <returns>True if we successfully moved to the next ScrVerse; False if we reached /// the end of the paragraph.</returns> /// ------------------------------------------------------------------------------------ public bool MoveNext() { InitializeParaContents(); if (m_ich > m_paraLength) { return(false); } m_ichVerseStart = m_ichTextStart = m_ich; TsRunInfo tsi; ITsTextProps ttpRun; string sPara = m_tssParaContents.Text; int nChapter = -1; // This is used to see if we found a chapter later. m_inVerseNum = false; m_inChapterNum = false; while (m_ich < m_paraLength) { ttpRun = m_tssParaContents.FetchRunInfoAt(m_ich, out tsi); // If this run is our verse number style if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber)) { // If there is already a verse in process, a new verse number run will terminate it. if (m_ichVerseStart != m_ich) { break; } // Assume the whole run is the verse number string sVerseNum = sPara.Substring(m_ich, tsi.ichLim - tsi.ichMin); int nVerseStart, nVerseEnd; ScrReference.VerseToInt(sVerseNum, out nVerseStart, out nVerseEnd); m_startRef.Verse = nVerseStart; m_endRef.Verse = nVerseEnd; m_ichVerseStart = m_ich; //set VerseStart at beg of verse number m_ich += sVerseNum.Length; m_ichTextStart = m_ich; m_inVerseNum = true; } // If this run is our chapter number style else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber)) { // If there is already a verse being processed, then the chapter number // run will end it if (m_ichVerseStart != m_ich) { break; } try { // Assume the whole run is the chapter number string sChapterNum = sPara.Substring(m_ich, tsi.ichLim - tsi.ichMin); nChapter = ScrReference.ChapterToInt(sChapterNum); m_startRef.Chapter = m_endRef.Chapter = nChapter; // Set the verse number to 1, since the first verse number after a // chapter is optional. If we happen to get a verse number in the // next run, this '1' will be overridden (though it will probably // still be a 1). m_startRef.Verse = m_endRef.Verse = 1; m_ichVerseStart = m_ich; //set VerseStart at beg of chapter number m_ich += sChapterNum.Length; m_ichTextStart = m_ich; m_inChapterNum = true; } catch (ArgumentException) { // ignore runs with invalid Chapter numbers m_ich += tsi.ichLim - tsi.ichMin; } } else // Process a text run. { // If it comes after a chapter number, then just return the // chapter number without adding the text. if (nChapter > 0) { break; } // skip to the next run m_ich += tsi.ichLim - tsi.ichMin; } } // determine if this verse is a complete paragraph, an empty para and/or a stanza break. m_isCompletePara = (m_ichVerseStart == 0 && m_ich == m_paraLength); if (string.IsNullOrEmpty(sPara)) { //m_isEmptyPara = true; m_isStanzaBreak = string.Equals(ScrStyleNames.StanzaBreak, ScrStyleNames.GetStyleName(m_para.Hvo, m_para.Cache)); } try { return((m_ich > m_ichVerseStart) || FirstTimeAtStanzaBreak); } finally { // Update the previous paragraph for the next time (but we do the update // in a 'finally' so that we can compare the current to the previous for // the return value). m_prevPara = m_para; } }