/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the Scripture reference of the specified annotation as string. /// </summary> /// <param name="ann">The specified annotation.</param> /// ------------------------------------------------------------------------------------ private string GetRefAsString(IScrScriptureNote ann) { BCVRef startRef = new BCVRef(ann.BeginRef); IScrBook book = m_scr.FindBook(startRef.Book); string bookName; // Book for note may not be in the project. if (book != null) { bookName = book.BestUIName; } else { IScrBookRef bookRef = Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.BooksOS[startRef.Book - 1]; ITsString tsName = bookRef.BookName.get_String(Cache.DefaultUserWs); if (tsName.Length == 0) { tsName = bookRef.BookName.BestAnalysisAlternative; } bookName = tsName.Text; } string titleText = ResourceHelper.GetResourceString("kstidScriptureTitle"); string introText = ResourceHelper.GetResourceString("kstidScriptureIntro"); return(BCVRef.MakeReferenceString(bookName, startRef, new BCVRef(ann.EndRef), m_scr.ChapterVerseSepr, m_scr.Bridge, titleText, introText)); }
public string ToString(bool includeReference, string bookId = null) { if (!includeReference) { return(ToString()); } if (bookId == null && !string.IsNullOrEmpty(BookCode)) { bookId = BookCode; } int bookNum; if (bookId == null) { bookId = string.Empty; bookNum = 1; } else { bookNum = BCVRef.BookToNumber(bookId); } var startRef = new BCVRef(bookNum, ChapterNumber, InitialStartVerseNumber); var endRef = new BCVRef(bookNum, ChapterNumber, LastVerseNum); return(BCVRef.MakeReferenceString(bookId, startRef, endRef, ":", "-") + " : " + ToString()); }
private string CreateReferenceForSplits(int bookNum, IList <Block> groupOfSplits) { int chapterNumber = groupOfSplits[0].ChapterNumber; BCVRef startRef = new BCVRef(bookNum, chapterNumber, groupOfSplits[0].InitialStartVerseNumber); BCVRef endRef = new BCVRef(bookNum, chapterNumber, groupOfSplits.Last().LastVerseNum); return(BCVRef.MakeReferenceString(startRef, endRef, ":", "-")); }
public string GetBlockReferenceString(Block block = null) { block = block ?? m_navigator.CurrentBlock; var startRef = new BCVRef(BCVRef.BookToNumber(CurrentBookId), block.ChapterNumber, block.InitialStartVerseNumber); var lastVerseInBlock = block.LastVerse; var endRef = (lastVerseInBlock <= block.InitialStartVerseNumber) ? startRef : new BCVRef(startRef.Book, startRef.Chapter, lastVerseInBlock); return(BCVRef.MakeReferenceString(startRef, endRef, ":", "-")); }
private void UpdateTitleAndFilenameForSectionRange() { if (m_cboStartSection.SelectedIndex < 0 || m_cboEndSection.SelectedIndex < 0) { return; } string sRef = BCVRef.MakeReferenceString(m_startRef, m_endRef, ".", "-"); UpdateTextBoxWithSelectedPassage(m_txtFilename, sRef, m_sFilenameTemplate); UpdateTextBoxWithSelectedPassage(m_txtTitle, sRef, m_sTitleTemplate); }
private string CreateReferenceForUnappliedSplit(int bookNum, IList <Block> unappliedSplit) { if (unappliedSplit.Count == 0) { throw new ArgumentException("unappliedSplit must contain at least one block.", "unappliedSplit"); } int chapterNumber = unappliedSplit[0].ChapterNumber; BCVRef startRef = new BCVRef(bookNum, chapterNumber, unappliedSplit[0].InitialStartVerseNumber); BCVRef endRef = new BCVRef(bookNum, chapterNumber, unappliedSplit[unappliedSplit.Count - 1].LastVerseNum); return(BCVRef.MakeReferenceString(startRef, endRef, ":", "-")); }
public static QuestionSections Generate(IEnumerable <string> sourceLines, Dictionary <string, string[]> alternatives) { m_canonicalBookNumbers = new HashSet <int>(); // Initialize the ID textbox. Category currCat = null; string currRef = null; int startRef = 0, endRef = 0; Section currSection = null; bool currSectionRefSet = false; Question currQuestion = null; List <Section> sections = new List <Section>(); List <Question> currentQuestions = new List <Question>(); int cAnswers = 0, cComments = 0, cCategories = 0; int kSectHeadMarkerLen = s_kSectionHead.Length; int kRefMarkerLen = s_kRefMarker.Length; int kQMarkerLen = s_kQuestionMarker.Length; int kAMarkerLen = s_kAnswerMarker.Length; int kCommentMarkerLen = s_kCommentMarker.Length; Debug.Assert(s_kDetailsMarker.Length == s_kOverviewMarker.Length); int kCategoryMarkerLen = s_kDetailsMarker.Length; Regex regexVerseNum = new Regex(@"\((?<startVerse>\d+)(-(?<endVerse>\d+))?\)$", RegexOptions.Compiled); foreach (string sLine in SourceFields(sourceLines)) { if (sLine.StartsWith(s_kQuestionMarker)) { if (currQuestion != null && cAnswers == 0 && cComments == 0) { // Question continued in a subsequent field. Just append the text to the existing question. currQuestion.Text += " " + sLine.Substring(kQMarkerLen).Trim(); } else { currQuestion = new Question(); currentQuestions.Add(currQuestion); currQuestion.Text = sLine.Substring(kQMarkerLen).Trim(); if (currRef != currSection.ScriptureReference) { currQuestion.ScriptureReference = currRef; currQuestion.StartRef = startRef; currQuestion.EndRef = endRef; } cAnswers = 0; cComments = 0; } } else if (sLine.StartsWith(s_kAnswerMarker)) { string currAnswer = sLine.Substring(kAMarkerLen).Trim(); if (!currCat.IsOverview) { Match match = regexVerseNum.Match(currAnswer); if (match.Success) { int startVerse = Int32.Parse(match.Result("${startVerse}")); string sEndVerse = match.Result("${endVerse}"); int endVerse = string.IsNullOrEmpty(sEndVerse) ? startVerse : Int32.Parse(sEndVerse); BCVRef bcvStart, bcvEnd; if (currQuestion.StartRef > 0) { bcvStart = new BCVRef(currQuestion.StartRef); bcvEnd = new BCVRef(currQuestion.EndRef); if (startVerse < bcvStart.Verse) { bcvStart.Verse = startVerse; } if (endVerse > bcvEnd.Verse) { bcvEnd.Verse = endVerse; } } else { bcvStart = new BCVRef(currSection.StartRef); bcvEnd = new BCVRef(currSection.EndRef); bcvStart.Verse = startVerse; bcvEnd.Verse = endVerse; } currQuestion.StartRef = bcvStart.BBCCCVVV; currQuestion.EndRef = bcvEnd.BBCCCVVV; currQuestion.ScriptureReference = BCVRef.MakeReferenceString( currSection.ScriptureReference.Substring(0, 3), bcvStart, bcvEnd, ".", "-"); } } string[] source = currQuestion.Answers; currQuestion.Answers = new string[cAnswers + 1]; if (source != null) { Array.Copy(source, currQuestion.Answers, cAnswers); } currQuestion.Answers[cAnswers++] = currAnswer; } else if (sLine.StartsWith(s_kCommentMarker)) { if (currQuestion != null) { string[] source = currQuestion.Notes; currQuestion.Notes = new string[cComments + 1]; if (source != null) { Array.Copy(source, currQuestion.Notes, cComments); } currQuestion.Notes[cComments++] = sLine.Substring(kCommentMarkerLen).Trim(); } } else { if (sLine.StartsWith(s_kRefMarker)) { currRef = sLine.Substring(kRefMarkerLen).Trim(); Parse(currRef, out startRef, out endRef); if (!currSectionRefSet) { currSection.ScriptureReference = currRef; currSection.StartRef = startRef; currSection.EndRef = endRef; currSectionRefSet = true; } } else if (sLine.StartsWith(s_kSectionHead)) { if (currentQuestions.Count > 0) { currCat.Questions = currentQuestions.ToArray(); currentQuestions.Clear(); } currSection = new Section(); sections.Add(currSection); cCategories = 1; currSection.Categories = new Category[cCategories]; currSection.Categories[0] = currCat = new Category(); currSection.Heading = sLine.Substring(kSectHeadMarkerLen).Trim(); currSectionRefSet = false; } else { bool isOverviewMarker = sLine.StartsWith(s_kOverviewMarker); if (isOverviewMarker || sLine.StartsWith(s_kDetailsMarker)) { if (currentQuestions.Count > 0) { currCat.Questions = currentQuestions.ToArray(); currentQuestions.Clear(); } if (currCat.Type != null || currCat.Questions != null) { currCat = new Category(); Category[] source = currSection.Categories; currSection.Categories = new Category[cCategories + 1]; if (source != null) { Array.Copy(source, currSection.Categories, cCategories); } currSection.Categories[cCategories++] = currCat; } currCat.Type = sLine.Substring(kCategoryMarkerLen).Trim(); currCat.IsOverview = isOverviewMarker; } } if (currQuestion != null) { currQuestion = null; cAnswers = 0; cComments = 0; } } } if (currCat != null && currentQuestions.Count > 0) { currCat.Questions = currentQuestions.ToArray(); } QuestionSections questionSections = new QuestionSections(); questionSections.Items = sections.ToArray(); GenerateAlternateForms(questionSections, alternatives); return(questionSections); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load a list of sections into the beginning and ending combo boxes for export. /// TEMPORARY: If it is the first (i.e., starting) section to export, only include /// sections that begin with a chapter. See TE-7287 for story to revert this. /// </summary> /// <param name="nBook"></param> /// ------------------------------------------------------------------------------------ private void LoadSectionsForBook(int nBook) { if (nBook == m_nBookForSections) { return; } m_fLoadingBookSections = true; using (new WaitCursor(this, true)) { cboFrom.Items.Clear(); cboTo.Items.Clear(); cboFrom.SelectedIndex = -1; cboTo.SelectedIndex = -1; IScrBook book = m_scr.FindBook(nBook); Debug.Assert(book != null); string sRef; // "{0} Intro: {1}" string sRefIntro = DlgResources.ResourceString("kstidOxesExportIntro"); // "{0}: {1}" string sRefPassage = DlgResources.ResourceString("kstidOxesExportRef"); ITsString tssHeading = null; // "(No text in section heading)" ITsString tssEmpty = TsStringUtils.MakeTss(DlgResources.ResourceString("kstidOxesExportEmptyHeading"), book.Cache.DefaultVernWs); BCVRef startRef; BCVRef endRef; IScrSection sect; IScrSection prevSect = null; int iSectionFrom = 0; for (int iSection = 0; iSection < book.SectionsOS.Count; ++iSection, prevSect = sect) { sect = book.SectionsOS[iSection]; sect.GetDisplayRefs(out startRef, out endRef); if (sect.HeadingOA != null) { // Get the first non-empty heading paragraph content. for (int j = 0; j < sect.HeadingOA.ParagraphsOS.Count; ++j) { IStTxtPara para = sect.HeadingOA.ParagraphsOS[j] as IStTxtPara; if (para != null && para.Contents.Length > 0) { tssHeading = para.Contents; break; } } } if (tssHeading == null || tssHeading.Length == 0) { tssHeading = tssEmpty; } else { // Replace embedded line separator characters with spaces. ITsStrBldr tsbFix = tssHeading.GetBldr(); for (int idx = tsbFix.Text.IndexOf(StringUtils.kChHardLB); idx >= 0; idx = tsbFix.Text.IndexOf(StringUtils.kChHardLB)) { tsbFix.Replace(idx, idx + 1, " ", null); } tssHeading = tsbFix.GetString(); } sRef = BCVRef.MakeReferenceString(startRef, endRef, m_scr.ChapterVerseSepr, m_scr.Bridge); sRef = string.Format(sect.IsIntro ? sRefIntro : sRefPassage, sRef, tssHeading.Text); // Only include intro section or sections that begin with a chapter // number run in the list of starting sections. This is currently // required because of the way the ScrSection.AdjustReferences relies // upon chapter numbers. ITsString tss = TsStringUtils.MakeTss(sRef, m_scr.Cache.DefaultVernWs); if (ValidStartingSection(sect, prevSect)) { iSectionFrom = cboFrom.Items.Add(new SectionCboItem(tss, iSection, iSection)); } cboTo.Items.Add(new SectionCboItem(tss, iSection, iSectionFrom)); } cboFrom.SelectedIndex = 0; cboTo.SelectedIndex = book.SectionsOS.Count - 1; } m_fLoadingBookSections = false; }
/// -------------------------------------------------------------------------------- /// <summary> /// Returns a string representation of the ORC location. /// </summary> /// <param name="scr">The SCR.</param> /// <returns></returns> /// -------------------------------------------------------------------------------- internal object ToString(IScripture scr) { return(BCVRef.MakeReferenceString(m_startRef, m_endRef, scr.ChapterVerseSepr, scr.Bridge, "Title", "Intro") + (m_moreInfo == null ? String.Empty : " " + m_moreInfo)); }
public string GetReferenceString(BCVRef startRef, BCVRef endRef) { return(BCVRef.MakeReferenceString(startRef, endRef, ":", "-")); }
private static void AdjustDetailQuestionRefBasedOnAnswer(Regex regexVerseNum, string currAnswer, Section currSection, Question currQuestion, ref bool currQuestionRefBasedOnAnswer) { Match match = regexVerseNum.Match(currAnswer); if (match.Success) { string sChapter = match.Result("${chapter}"); int chapter = string.IsNullOrEmpty(sChapter) ? 0 : Int32.Parse(sChapter); int startVerse = Int32.Parse(match.Result("${startVerse}")); string sEndVerse = match.Result("${endVerse}"); int endVerse = string.IsNullOrEmpty(sEndVerse) ? startVerse : Int32.Parse(sEndVerse); while ((match = match.NextMatch()).Success) { sEndVerse = match.Result("${endVerse}"); endVerse = string.IsNullOrEmpty(sEndVerse) ? Int32.Parse(match.Result("${startVerse}")) : Int32.Parse(sEndVerse); // Answer might have multiple parts, not ordered according to verse ref. if (endVerse < startVerse) { var temp = startVerse; startVerse = endVerse; endVerse = temp; } } BCVRef bcvStart = new BCVRef(currSection.StartRef); BCVRef bcvEnd = new BCVRef(currSection.EndRef); // if reference in the answer is not in range for the current section, disregard it. bool inSectionRange = true; if (chapter == 0) { inSectionRange = (bcvStart.Chapter == bcvEnd.Chapter - 1) || (startVerse >= bcvStart.Verse && endVerse <= bcvEnd.Verse); } else { if ((chapter < bcvStart.Chapter || chapter > bcvEnd.Chapter) || (chapter == bcvStart.Chapter && startVerse < bcvStart.Verse) || (chapter == bcvEnd.Chapter && startVerse > bcvEnd.Verse)) { inSectionRange = false; } } if (inSectionRange) { if (currQuestion.StartRef <= 0) { bcvStart.Verse = startVerse; bcvEnd.Verse = endVerse; } else { bcvStart = new BCVRef(currQuestion.StartRef); bcvEnd = new BCVRef(currQuestion.EndRef); if (chapter > 0) { bcvStart.Chapter = bcvEnd.Chapter = chapter; } if (bcvStart.Chapter == bcvEnd.Chapter - 1 && bcvStart.Verse > bcvEnd.Verse) { if (startVerse >= bcvStart.Verse && endVerse > bcvEnd.Verse) { // Question applies to a verse found wholly in the first chapter of the range bcvStart.Verse = startVerse; bcvEnd.Chapter = bcvStart.Chapter; bcvEnd.Verse = endVerse; } else if (startVerse < bcvStart.Verse && endVerse <= bcvEnd.Verse) { bcvStart.Verse = startVerse; bcvStart.Chapter = bcvEnd.Chapter; bcvEnd.Verse = endVerse; } } else if (bcvStart.Chapter == bcvEnd.Chapter) { // If the current ref is based on (a previous) answer, we only want to // expand the reference range, not contract it. If it's based on the // section, then we want to set it to exactly what's specifiedf in the // answer. if (!currQuestionRefBasedOnAnswer || startVerse < bcvStart.Verse) { bcvStart.Verse = startVerse; } if (!currQuestionRefBasedOnAnswer || endVerse > bcvEnd.Verse || chapter > 0) { bcvEnd.Verse = endVerse; } } } currQuestion.StartRef = bcvStart.BBCCCVVV; currQuestion.EndRef = bcvEnd.BBCCCVVV; currQuestion.ScriptureReference = BCVRef.MakeReferenceString( currSection.ScriptureReference.Substring(0, 3), bcvStart, bcvEnd, ".", "-"); currQuestionRefBasedOnAnswer = true; } } }