public void Equals_FollowsGuidelines() { var sectionCur = Cache.ServiceLocator.GetInstance <IScrSectionFactory>().CreateScrSection( m_genesis, 0, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs), false); var stPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; using (var verseSet1 = new ScrVerseSet(stPara)) { using (var verseSet2 = new ScrVerseSet(stPara)) { using (var verseSet3 = new ScrVerseSet(stPara)) { // Iterate through the verses in the paragraph Assert.IsTrue(verseSet1.MoveNext()); Assert.IsTrue(verseSet2.MoveNext()); Assert.IsTrue(verseSet3.MoveNext()); var x = verseSet1.Current; var y = verseSet2.Current; var z = verseSet3.Current; Assert.IsTrue(x.Equals(x)); Assert.AreEqual(x.Equals(y), y.Equals(x)); Assert.AreEqual(x.Equals(z), x.Equals(y) && y.Equals(z)); Assert.AreEqual(x.Equals(y), x.Equals(y)); Assert.IsFalse(x.Equals(null)); } } } }
public void MoveNext_EmptyPara() { IScrSection section = AddSectionToMockedBook(m_genesis); IScrTxtPara emptyPara = AddEmptyPara(section, ScrStyleNames.SpeechLine1); // Create and iterate through the verses in the StText. using (ScrVerseSet verseSet = new ScrVerseSet(emptyPara)) { Assert.IsFalse(verseSet.MoveNext(), "The iterator provided a ScrVerse for an empty para that wasn't a Stanza Break."); } }
public void MoveNext_StanzaBreak() { IScrSection section = AddSectionToMockedBook(m_genesis); IScrTxtPara emptyPara = AddEmptyPara(section, ScrStyleNames.StanzaBreak); // Create and iterate through the verses in the StText. using (ScrVerseSet verseSet = new ScrVerseSet(emptyPara)) { Assert.IsTrue(verseSet.MoveNext()); ScrVerse verse = verseSet.Current; Assert.IsTrue(verse.Text == null || string.IsNullOrEmpty(verse.Text.Text)); Assert.AreEqual(ScrStyleNames.StanzaBreak, verse.Para.StyleName); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }
public void MoveNext_ImplicitChapter1AndVerse1() { var sectionCur = Cache.ServiceLocator.GetInstance <IScrSectionFactory>().CreateScrSection( m_genesis, 0, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs), false); var stPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; using (var verseSet = new ScrVerseSet(stPara)) { // Iterate through the verses in the paragraph Assert.IsTrue(verseSet.MoveNext()); var verse = verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }
public void MoveNext_NonNumericChapter() { IScrSection sectionCur = Cache.ServiceLocator.GetInstance <IScrSectionFactory>().CreateSection( m_genesis, 0, false, true, true); IScrTxtPara contentPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); strBldr.Replace(0, strBldr.Length, "A", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, " Verse Two. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); contentPara.Contents = strBldr.GetString(); using (ScrVerseSet verseSet = new ScrVerseSet(contentPara)) { // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("AVerse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("2 Verse Two. ", verse.Text.Text); Assert.AreEqual(01001002, verse.StartRef); Assert.AreEqual(01001002, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }
public void MoveNext_EmptyPara() { CheckDisposed(); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); StTxtPara emptyPara = AddEmptyPara(section, ScrStyleNames.SpeechLine1); section.AdjustReferences(); // Create and iterate through the verses in the StText. ScrTxtPara emptyScrPara = new ScrTxtPara(m_inMemoryCache.Cache, emptyPara.Hvo); ScrVerseSet verseSet = new ScrVerseSet(emptyScrPara); Assert.IsFalse(verseSet.MoveNext(), "The iterator provided a ScrVerse for an empty para that wasn't a Stanza Break."); }
public void MoveNext_StanzaBreak() { CheckDisposed(); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); StTxtPara emptyPara = AddEmptyPara(section, ScrStyleNames.StanzaBreak); section.AdjustReferences(); // Create and iterate through the verses in the StText. ScrTxtPara emptyScrPara = new ScrTxtPara(m_inMemoryCache.Cache, emptyPara.Hvo); ScrVerseSet verseSet = new ScrVerseSet(emptyScrPara); Assert.IsTrue(verseSet.MoveNext()); VerifyScrVerse((ScrVerse)verseSet.Current, m_inMemoryCache.Cache, null, ScrStyleNames.StanzaBreak, 01001001, 01001001); Assert.IsFalse(verseSet.MoveNext()); }
public void MoveNext_NonNumericChapter() { CheckDisposed(); IScrSection sectionCur = ScrSection.CreateSectionWithEmptyParas(m_genesis, 0, false); TsStringAccessor heading = ((StTxtPara)sectionCur.HeadingOA.ParagraphsOS[0]).Contents; ITsStrBldr strBldr = heading.UnderlyingTsString.GetBldr(); strBldr.Replace(0, strBldr.Length, "My aching head!", null); heading.UnderlyingTsString = strBldr.GetString(); TsStringAccessor content = ((StTxtPara)sectionCur.ContentOA.ParagraphsOS[0]).Contents; strBldr = content.UnderlyingTsString.GetBldr(); strBldr.Replace(0, strBldr.Length, "A", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, " Verse Two. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); content.UnderlyingTsString = strBldr.GetString(); sectionCur.AdjustReferences(); ScrTxtPara stPara = new ScrTxtPara(Cache, sectionCur.ContentOA.ParagraphsOS.HvoArray[0]); ScrVerseSet verseSet = new ScrVerseSet(stPara); // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("AVerse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("2 Verse Two. ", verse.Text.Text); Assert.AreEqual(01001002, verse.StartRef); Assert.AreEqual(01001002, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); }
public void MoveNext_ImplicitChapter1AndVerse1() { CheckDisposed(); IScrSection sectionCur = ScrSection.CreateSectionWithEmptyParas(m_genesis, 0, false); TsStringAccessor heading = ((StTxtPara)sectionCur.HeadingOA.ParagraphsOS[0]).Contents; ITsStrBldr strBldr = heading.UnderlyingTsString.GetBldr(); strBldr.Replace(0, strBldr.Length, "My aching head!", null); heading.UnderlyingTsString = strBldr.GetString(); TsStringAccessor content = ((StTxtPara)sectionCur.ContentOA.ParagraphsOS[0]).Contents; strBldr = content.UnderlyingTsString.GetBldr(); strBldr.Replace(0, strBldr.Length, "Verse One. ", null); content.UnderlyingTsString = strBldr.GetString(); sectionCur.AdjustReferences(); ScrTxtPara stPara = new ScrTxtPara(Cache, sectionCur.ContentOA.ParagraphsOS.HvoArray[0]); ScrVerseSet verseSet = new ScrVerseSet(stPara); // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Navigate to the beginning of the text of the first (implicit or explicit) chapter /// in the first paragraph in the specified scripture section. If a chapter isn't /// found then the IP is put at the beginning of the content paragraph. /// </summary> /// <param name="iBook">0-based index of the book (in this view)</param> /// <param name="section">The section (in the given book, as displayed in this view) /// </param> /// ------------------------------------------------------------------------------------ private void GoToFirstChapterInSection(int iBook, IScrSection section) { int ichChapterStart = 0; using (ScrVerseSet verseSet = new ScrVerseSet((IScrTxtPara)section.ContentOA[0])) { if (verseSet.MoveNext()) { ScrVerse verse = verseSet.Current; if (!verse.VerseNumberRun) ichChapterStart = verse.TextStartIndex; } } ScrReference scrRef = new ScrReference(section.VerseRefStart, m_scr.Versification); GoToPosition(scrRef, iBook, section, 0, ichChapterStart); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a verse and return the text of the verse in one or more /// <see cref="VerseTextSubstring"/> objects. /// </summary> /// <param name="scr">The scripture.</param> /// <param name="targetRef">The verse reference to look for</param> /// <returns> /// The <see cref="VerseTextSubstring"/> objects, each representing /// one paragraph worth of verse text (e.g., to deal with poetry) /// </returns> /// <remarks>Verses would not normally be split across sections, but there are a few /// places, such as the end of I Cor. 12, where it can happen. /// ENHANCE: Logicially, this method probably really belongs on Scripture, but currently /// that FDO doesn't reference ScrUtils (which is where ScrReference is). It probably /// could reference it, if we wanted it to. Another option would be to create an /// extension method for it, but I'm not sure where it would go. /// </remarks> /// ------------------------------------------------------------------------------------ public static IEnumerable<VerseTextSubstring> GetVerseText(IScripture scr, ScrReference targetRef) { if (scr.Versification != targetRef.Versification) targetRef = new ScrReference(targetRef, scr.Versification); List<VerseTextSubstring> verseText = new List<VerseTextSubstring>(); // Find the book that the reference is in IScrBook book = scr.FindBook(targetRef.Book); if (book == null) return verseText; if (targetRef.IsBookTitle) { foreach (IStTxtPara para in book.TitleOA.ParagraphsOS) { verseText.Add(new VerseTextSubstring(para.Contents, -1, para.IndexInOwner, 0, ScrBookTags.kflidTitle)); } return verseText; } int iSection = 0; // Look through the sections for the target reference foreach (IScrSection section in book.SectionsOS) { if (!section.ContainsReference(targetRef)) { if (verseText.Count > 0) return verseText; } else { int iPara = 0; // Look through each paragraph in the section foreach (IScrTxtPara para in section.ContentOA.ParagraphsOS) { // Search for target reference in the verses in the paragraph using (ScrVerseSet verseSet = new ScrVerseSet(para)) { foreach (ScrVerse verse in verseSet) { if (verse.StartRef <= targetRef && targetRef <= verse.EndRef) { // If the paragraph has a chapter number, the verse iterator // returns this as a separate string with the same reference // as the following verse. // We want to return the verse string, not the chapter number // run, so we skip a string that has only numeric characters. ITsString verseTextInPara = verse.Text; if (verse.Text.RunCount > 0 && verse.Text.Style(0) == ScrStyleNames.VerseNumber) { verseTextInPara = verseTextInPara.Substring(verse.Text.get_LimOfRun(0)); } if (!IsNumber(verseTextInPara.Text)) // skip chapter number strings { int ichStart = (verseText.Count == 0) ? verse.TextStartIndex : 0; verseText.Add(new VerseTextSubstring(verseTextInPara, iSection, iPara, ichStart, ScrSectionTags.kflidContent)); break; } } else if (verseText.Count > 0) return verseText; } } iPara++; } } iSection++; } return verseText; }
public void MoveNext_NonNumericChapter() { IScrSection sectionCur = Cache.ServiceLocator.GetInstance<IScrSectionFactory>().CreateSection( m_genesis, 0, false, true, true); IScrTxtPara contentPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); strBldr.Replace(0, strBldr.Length, "A", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, "2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, " Verse Two. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); contentPara.Contents = strBldr.GetString(); using (ScrVerseSet verseSet = new ScrVerseSet(contentPara)) { // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("AVerse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("2 Verse Two. ", verse.Text.Text); Assert.AreEqual(01001002, verse.StartRef); Assert.AreEqual(01001002, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Look for the given picture's ORC in the given verse. /// </summary> /// <param name="targetRef">The verse reference to look for</param> /// <param name="hvoPict">The hvo of the picture to look for.</param> /// <param name="iSection">The index of the section where the ORC was found.</param> /// <param name="iPara">The index of the para where the ORC was found.</param> /// <param name="ichOrcPos">The character position of the ORC in the paragraph.</param> /// <returns> /// <c>true</c> if the given picture is found in the given verse. /// </returns> /// ------------------------------------------------------------------------------------ public bool FindPictureInVerse(ScrReference targetRef, int hvoPict, out int iSection, out int iPara, out int ichOrcPos) { CheckDisposed(); iSection = iPara = ichOrcPos = -1; // Find the book that the reference is in IScrBook book = ScrBook.FindBookByID(m_scr, targetRef.Book); if (book == null) return false; iSection = 0; // Look through the sections for the target reference foreach (ScrSection section in book.SectionsOS) { if (section.ContainsReference(targetRef)) { iPara = 0; // Look through each paragraph in the section foreach (StTxtPara para in section.ContentOA.ParagraphsOS) { // Search for target reference in the verses in the paragraph ScrTxtPara scrPara = new ScrTxtPara(m_cache, para.Hvo); ScrVerseSet verseSet = new ScrVerseSet(scrPara); foreach (ScrVerse verse in verseSet) { if (verse.StartRef <= targetRef && targetRef <= verse.EndRef) { // If the paragraph has a chapter number, the verse iterator // returns this as a separate string with the same reference // as the following verse. // We want to return the verse string, not the chapter number // run, so we skip a string that has only numeric characters. ITsString tssVerse = verse.Text; for (int iRun = 0; iRun < tssVerse.RunCount; iRun++) { string sRun = tssVerse.get_RunText(iRun); if (sRun.Length == 1 && sRun[0] == StringUtils.kchObject) { string str = tssVerse.get_Properties(iRun).GetStrPropValue( (int)FwTextPropType.ktptObjData); if (!String.IsNullOrEmpty(str) && str[0] == (char)(int)FwObjDataTypes.kodtGuidMoveableObjDisp) { Guid guid = MiscUtils.GetGuidFromObjData(str.Substring(1)); if (m_cache.GetIdFromGuid(guid) == hvoPict) { ichOrcPos = tssVerse.get_MinOfRun(iRun) + verse.VerseStartIndex; return true; } } } } } } iPara++; } } iSection++; } return false; }
public void MoveNext_SpacesInVerses() { CheckDisposed(); ScrSection sectionCur = new ScrSection(); m_genesis.SectionsOS.Append(sectionCur); // Create a section head for this section sectionCur.HeadingOA = new StText(); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); paraBldr.AppendRun("My aching head!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.HeadingOAHvo); sectionCur.ContentOA = new StText(); paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun(" Verse Two. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse Three.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun(" ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); StTxtPara para = paraBldr.CreateParagraph(sectionCur.ContentOA.Hvo); sectionCur.AdjustReferences(); ScrTxtPara stPara = new ScrTxtPara(Cache, para.Hvo); ScrVerseSet verseSet = new ScrVerseSet(stPara); // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("1", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("2 Verse Two. ", verse.Text.Text); Assert.AreEqual(01001002, verse.StartRef); Assert.AreEqual(01001002, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("3Verse Three.", verse.Text.Text); Assert.AreEqual(01001003, verse.StartRef); Assert.AreEqual(01001003, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("4 ", verse.Text.Text); Assert.AreEqual(01001004, verse.StartRef); Assert.AreEqual(01001004, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); }
public void MoveNext_SpacesInVerses_ChapterNumberSeparate() { IScrSection sectionCur = AddSectionToMockedBook(m_genesis); // Create a section head for this section AddSectionHeadParaToSection(sectionCur, "My aching head!", ScrStyleNames.SectionHead); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun(" Verse Two. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse Three.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun(" ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrTxtPara para = (IScrTxtPara)paraBldr.CreateParagraph(sectionCur.ContentOA); using (ScrVerseSet verseSet = new ScrVerseSet(para)) { // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("1", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("2 Verse Two. ", verse.Text.Text); Assert.AreEqual(01001002, verse.StartRef); Assert.AreEqual(01001002, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("3Verse Three.", verse.Text.Text); Assert.AreEqual(01001003, verse.StartRef); Assert.AreEqual(01001003, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = verseSet.Current; Assert.AreEqual("4 ", verse.Text.Text); Assert.AreEqual(01001004, verse.StartRef); Assert.AreEqual(01001004, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }
public void Equals_FollowsGuidelines() { var sectionCur = Cache.ServiceLocator.GetInstance<IScrSectionFactory>().CreateScrSection( m_genesis, 0, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs), false); var stPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; using (var verseSet1 = new ScrVerseSet(stPara)) { using (var verseSet2 = new ScrVerseSet(stPara)) { using (var verseSet3 = new ScrVerseSet(stPara)) { // Iterate through the verses in the paragraph Assert.IsTrue(verseSet1.MoveNext()); Assert.IsTrue(verseSet2.MoveNext()); Assert.IsTrue(verseSet3.MoveNext()); var x = verseSet1.Current; var y = verseSet2.Current; var z = verseSet3.Current; Assert.IsTrue(x.Equals(x)); Assert.AreEqual(x.Equals(y), y.Equals(x)); Assert.AreEqual(x.Equals(z), x.Equals(y) && y.Equals(z)); Assert.AreEqual(x.Equals(y), x.Equals(y)); Assert.IsFalse(x.Equals(null)); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a verse and return the text of the verse in one or more /// <see cref="VerseTextSubstring"/> objects. /// </summary> /// <param name="scr">The scripture.</param> /// <param name="targetRef">The verse reference to look for</param> /// <param name="ichStart">The starting character where the (first part of the) verse /// text is located within the (first) containing paragraph</param> /// <returns> /// A list of <see cref="VerseTextSubstring"/> objects, each representing /// one paragraph worth of verse text (e.g., to deal with poetry) /// </returns> /// <remarks>Verses would not normally be split across sections, but there are a few /// places, such as the end of I Cor. 12, where it can happen. /// </remarks> /// ------------------------------------------------------------------------------------ public static List<VerseTextSubstring> GetVerseText(IScripture scr, ScrReference targetRef, out int ichStart) { ichStart = -1; if (scr.Versification != targetRef.Versification) targetRef = new ScrReference(targetRef, scr.Versification); List<VerseTextSubstring> verseText = new List<VerseTextSubstring>(); // Find the book that the reference is in IScrBook book = ScrBook.FindBookByID(scr, targetRef.Book); if (book == null) return verseText; if (targetRef.IsBookTitle) { foreach (StTxtPara para in book.TitleOA.ParagraphsOS) { verseText.Add(new VerseTextSubstring(para.Contents.UnderlyingTsString, -1, para.IndexInOwner, (int)ScrBook.ScrBookTags.kflidTitle)); ichStart = 0; } return verseText; } int iSection = 0; // Look through the sections for the target reference foreach (ScrSection section in book.SectionsOS) { if (!section.ContainsReference(targetRef)) { if (verseText.Count > 0) return verseText; } else { int iPara = 0; // Look through each paragraph in the section foreach (StTxtPara para in section.ContentOA.ParagraphsOS) { // Search for target reference in the verses in the paragraph ScrTxtPara scrPara = new ScrTxtPara(scr.Cache, para.Hvo); ScrVerseSet verseSet = new ScrVerseSet(scrPara); foreach (ScrVerse verse in verseSet) { if (verse.StartRef <= targetRef && targetRef <= verse.EndRef) { // If the paragraph has a chapter number, the verse iterator // returns this as a separate string with the same reference // as the following verse. // We want to return the verse string, not the chapter number // run, so we skip a string that has only numeric characters. ITsString verseTextInPara = verse.Text; if (verse.Text.RunCount > 0) { string styleName = verse.Text.get_PropertiesAt(0).GetStrPropValue( (int)FwTextPropType.ktptNamedStyle); if (styleName == ScrStyleNames.VerseNumber) verseTextInPara = StringUtils.Substring(verseTextInPara, verse.Text.get_LimOfRun(0)); } if (!IsNumber(verseTextInPara.Text)) // skip chapter number strings { if (verseText.Count == 0) ichStart = verse.TextStartIndex; verseText.Add(new VerseTextSubstring(verseTextInPara, iSection, iPara, (int)ScrSection.ScrSectionTags.kflidContent)); break; } } else if (verseText.Count > 0) return verseText; } iPara++; } } iSection++; } return verseText; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Navigate to the beginning of the text of the first (implicit or explicit) chapter /// in the first paragraph in the specified scripture section. If a chapter isn't /// found then the IP is put at the beginning of the content paragraph. /// </summary> /// <param name="iBook">0-based index of the book (in this view)</param> /// <param name="section">The section (in the given book, as displayed in this view) /// </param> /// ------------------------------------------------------------------------------------ private void GoToFirstChapterInSection(int iBook, ScrSection section) { int ichChapterStart = 0; ScrVerseSet verseSet = new ScrVerseSet(new ScrTxtPara(m_cache, section[0].Hvo)); if (verseSet.MoveNext()) { ScrVerse verse = (ScrVerse)verseSet.Current; if (!verse.VerseNumberRun) ichChapterStart = verse.TextStartIndex; } ScrReference scrRef = new ScrReference(section.VerseRefStart, m_scr.Versification); GoToPosition(scrRef, iBook, section, 0, ichChapterStart); }
public void MoveNext_ImplicitChapter1AndVerse1() { var sectionCur = Cache.ServiceLocator.GetInstance<IScrSectionFactory>().CreateScrSection( m_genesis, 0, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs), false); var stPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; using (var verseSet = new ScrVerseSet(stPara)) { // Iterate through the verses in the paragraph Assert.IsTrue(verseSet.MoveNext()); var verse = verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); } }