Exemplo n.º 1
0
        private static void CreateFriendlyTexts(List <BIBLETEXTINFO> list)
        {
            for (int i = 0; i < list.Count; ++i)
            {
                var       item  = list[i];
                BCVSTRUCT start = new BCVSTRUCT();
                BCVSTRUCT end   = new BCVSTRUCT();

                ParseForBCVStructs(item.bcv, ref start, ref end);
                if (string.IsNullOrEmpty(start.Book))
                {
                    continue;
                }
                else
                {
                    if (string.IsNullOrEmpty(end.Book))
                    {
                        item.FriendlyText = GetBookName_abbr(start.Book) + " " + start.Chapter + ":" + start.Verse;
                    }
                    else
                    {
                        if (start.Verse == "1" && end.Verse == VerseCount(end.Book, end.Chapter).ToString())
                        {
                            item.FriendlyText = GetBookName_short(start.Book) + " " + start.Chapter;
                        }
                        else
                        {
                            item.FriendlyText = GetBookName_abbr(start.Book) + " " + start.Chapter + ":" + start.Verse + "-" + end.Verse;
                        }
                    }
                }
                list[i] = item;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get verse text for a single bcv.
 /// </summary>
 /// <param name="start">Specified bcv.</param>
 /// <returns>Single verse text.</returns>
 private static string GetSingleVerse(BCVSTRUCT start)
 {
     try
     {
         foreach (XmlElement BOOK in KJVBibleNode.ChildNodes)
         {
             if (BOOK.Attributes["NAME"].Value == start.Book)
             {
                 foreach (XmlElement CHAPTER in BOOK.ChildNodes)
                 {
                     if (CHAPTER.Attributes["ID"].Value == start.Chapter)
                     {
                         foreach (XmlElement VERSE in CHAPTER.ChildNodes)
                         {
                             if (VERSE.Attributes["BCV"].Value == start.bcv)
                             {
                                 return(VERSE.Attributes["BCV"].Value + " " + VERSE.InnerText);
                             }
                         }
                         break;
                     }
                 }
                 break;
             }
         }
         return(null);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Concatenates book, chapter and verse to form a single BCV.
 /// </summary>
 /// <param name="input">The BCVStruct.</param>
 /// <returns>bcv</returns>
 private static string GenerateBCVString(BCVSTRUCT input)
 {
     if (!string.IsNullOrEmpty(input.Book) && !string.IsNullOrEmpty(input.Chapter) && !string.IsNullOrEmpty(input.Verse))
     {
         return(input.Book.ToUpper() + "." + input.Chapter + "." + input.Verse);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Check if the string is formatted in a way that is usable by the program.
        /// </summary>
        /// <param name="stringToParse">The string to be parsed.</param>
        /// <param name="start">The beginning bcv structure.</param>
        /// <param name="end">The ending bcv structure (for ranges).</param>
        /// <returns>The bcv to display.</returns>
        public static string ParseForBCVStructs(string stringToParse, ref BCVSTRUCT start, ref BCVSTRUCT end)
        {
            if (Regex.IsMatch(stringToParse, @"\w{1,3}\.\d{1,3}\.\d{1,3}\-\w{1,3}\.\d{1,3}\.\d{1,3}"))
            {
                int iPosRange = stringToParse.IndexOf(RANGE_SEPARATOR);

                var startString = stringToParse.Remove(iPosRange);
                startString   = startString.Replace("-", string.Empty);
                start.bcv     = startString;
                start.Book    = startString.Remove(startString.IndexOf("."));
                start.Chapter = startString.Remove(0, startString.IndexOf(".") + 1);
                start.Chapter = start.Chapter.Remove(start.Chapter.IndexOf("."));
                start.Verse   = startString.Remove(0, startString.LastIndexOf(".") + 1);

                startString = stringToParse.Remove(0, (iPosRange + 1));
                end.bcv     = startString;
                end.Book    = startString.Remove(startString.IndexOf("."));
                end.Chapter = startString.Remove(0, startString.IndexOf(".") + 1);
                end.Chapter = end.Chapter.Remove(end.Chapter.IndexOf("."));
                end.Verse   = startString.Remove(0, startString.LastIndexOf(".") + 1);

                startString = stringToParse.Remove(iPosRange);

                return(start.bcv + "-" + end.bcv);
            }
            else
            {
                var startString = Regex.Match(stringToParse, @"\w{1,3}\.\d{1,3}\.\d{1,3}").Value;
                if (!string.IsNullOrEmpty(startString))
                {
                    var bcv = startString;
                    start.bcv     = bcv;
                    start.Book    = bcv.Remove(bcv.IndexOf("."));
                    start.Chapter = bcv.Remove(0, bcv.IndexOf(".") + 1);
                    start.Chapter = start.Chapter.Remove(start.Chapter.IndexOf("."));
                    start.Verse   = bcv.Remove(0, bcv.LastIndexOf(".") + 1);

                    end.bcv     = null;
                    end.Book    = null;
                    end.Chapter = null;
                    end.Chapter = null;
                    end.Verse   = null;

                    return(start.bcv);
                }
            }
            return("NOT_A_VERSE");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get multiple verses from a range of books.
        /// </summary>
        /// <param name="start">The beginning bcv.</param>
        /// <param name="end">The ending bcv.</param>
        /// <returns>List of verse texts.</returns>
        private static List <string> GetMultipleVersesDifferentBooks(BCVSTRUCT start, BCVSTRUCT end)
        {
            XmlNode       BOOK = null;
            List <string> list = new List <string>();
            BCVSTRUCT     bookStart = new BCVSTRUCT(), bookEnd = new BCVSTRUCT();
            string        book;

            foreach (XmlNode BOOKSample in KJVBibleNode.ChildNodes)
            {
                if (BOOKSample.Attributes["NAME"].Value == start.Book)
                {
                    BOOK = BOOKSample;
                }
            }
            do
            {
                book = BOOK.Attributes["NAME"].Value;
                if (book == start.Book)//read the first book from the specified chapter and verse to the end of the book
                {
                    bookStart = start;

                    bookEnd.Book    = start.Book;
                    bookEnd.Chapter = ChapterCount(bookEnd.Book).ToString();
                    bookEnd.Verse   = VerseCount(bookEnd.Book, bookEnd.Chapter).ToString();
                }
                else if (book == end.Book)//read the last book from the beginning to the specified chapter and verse
                {
                    bookStart.Book    = end.Book;
                    bookStart.Chapter = "1";
                    bookStart.Verse   = "1";

                    bookEnd = end;
                }
                else//read the chapter from the beginning to the end
                {
                    bookStart.Book    = book;
                    bookStart.Chapter = "1";
                    bookStart.Verse   = "1";

                    bookEnd.Book    = book;
                    bookEnd.Chapter = ChapterCount(bookEnd.Book).ToString();
                    bookEnd.Verse   = VerseCount(bookEnd.Book, bookEnd.Chapter).ToString();
                }
                list.AddRange(GetMultipleVersesSameBook(book, bookStart, bookEnd));
                BOOK = BOOK.NextSibling;
            } while (book != end.Book);
            return(list);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Handler for getting multiple verses.
 /// </summary>
 /// <param name="start">Specified beginning bcv.</param>
 /// <param name="end">Specified ending bcv.</param>
 /// <returns>List of verse texts.</returns>
 private static List <string> GetMultipleVerses(BCVSTRUCT start, BCVSTRUCT end)
 {
     if (start.Book == end.Book)
     {
         if (start.Chapter == end.Chapter)
         {
             return(GetMultipleVersesSameBookSameChapter(start.Book, int.Parse(start.Chapter) - 1, int.Parse(start.Verse) - 1, int.Parse(end.Verse) - 1));
         }
         else
         {
             return(GetMultipleVersesSameBook(start.Book, start, end));
         }
     }
     else
     {
         return(GetMultipleVersesDifferentBooks(start, end));
     }
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Carries out the second step of parsing, by separating the string into sub-blocks.
        ///     It makes use of the inblock separator. Each sub-block is first passed to a subsidiary function to properly parse it,
        ///     then passed to the third parsing function.
        /// <para>For example:</para>
        /// <para>
        ///     HEBREWS11:1-6,12 becomes: HEBREWS11:1-6 and 12
        /// </para>
        /// </summary>
        /// <param name="stringToParse">The string to parse.</param>
        /// <param name="listOfBCVRanges">The list to be updated passed by reference.</param>
        private static void ParseString1(List <BCVRANGE> listOfBCVRanges, string stringToParse)
        {
            if (stringToParse.Length < 1)
            {
                return;
            }

            stringToParse = stringToParse.Trim();
            //ensure uniformity in parsing all strings: inblockSeparator must exist in all strings
            if (!stringToParse.EndsWith(INBLOCK_SEPARATOR.ToString()))
            {
                stringToParse += INBLOCK_SEPARATOR;
            }

            BCVSTRUCT bibleTextCurrent = new BCVSTRUCT()
            {
                Book = null
            };
            bool          addedVerse = false;
            StringBuilder builder    = new StringBuilder(stringToParse.Length);

            for (int i = 0; i < stringToParse.Length; i++)
            {
                if (stringToParse[i] == INBLOCK_SEPARATOR)
                {
                    if (builder.ToString().Length > 0)
                    {
                        if (!string.IsNullOrEmpty(bibleTextCurrent.Book))
                        {
                            builder = new StringBuilder(SetStringForInblockSeparator(bibleTextCurrent, builder.ToString(), addedVerse));
                        }
                        bibleTextCurrent = ParseString2(builder.ToString(), listOfBCVRanges, out addedVerse);
                    }
                    builder.Clear();//clear builder to accommodate next string
                }
                else
                {
                    builder.Append(stringToParse[i]);
                }
            }
            return;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Parses user input to a form that the program can later use to display verses
        /// </summary>
        /// <param name="stringToParse">String passed to be parsed</param>
        /// <returns></returns>
        public static List <BIBLETEXTINFO> ParseStringToVerse(string stringToParse)
        {
            if (!string.IsNullOrEmpty(stringToParse) && !string.IsNullOrWhiteSpace(stringToParse))
            {
                List <BIBLETEXTINFO> listOfBTI = new List <BIBLETEXTINFO>();

                List <BCVRANGE> listOfBCVRanges = new List <BCVRANGE>();

                listOfBCVRanges = ParseString(stringToParse);

                for (int i = 0; i < listOfBCVRanges.Count; i++)
                {
                    BCVSTRUCT     START         = listOfBCVRanges[i].Start;
                    BCVSTRUCT     END           = listOfBCVRanges[i].End;
                    BIBLETEXTINFO bibleTextInfo = new BIBLETEXTINFO()
                    {
                        verse = string.Empty
                    };

                    //Update bcv to be displayed
                    if (END.Book == null)//no range: show single bcv
                    {
                        bibleTextInfo.bcv = START.bcv;
                        listOfBTI.Add(bibleTextInfo);
                    }
                    else//range: show start and end bcv's
                    {
                        bibleTextInfo.bcv = START.bcv + RANGE_SEPARATOR + END.bcv;
                        listOfBTI.Add(bibleTextInfo);
                    }
                    //end of update
                }
                CreateFriendlyTexts(listOfBTI);
                return(listOfBTI);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///     A subsidiary parsing function to the inblock separator function.
        ///     It checks the string passed and correctly supplies missing information
        ///     such as BOOK name and/or CHAPTER.
        /// </summary>
        /// <remarks>
        ///     For example:
        ///     From 12 in HEBREWS11:1-6 and 12 separated in the calling function,
        ///     the function returns HEBREWS11:12 for the inblock separated string "12".
        /// </remarks>
        /// <param name="BCVCurrent">
        ///     BCVstruct containing details of the most previous verse handled.
        ///     It gives information for the sub-block to be parsed.</param>
        /// <param name="stringToParse"></param>
        /// <returns></returns>
        private static string SetStringForInblockSeparator(BCVSTRUCT BCVCurrent, string stringToParse, bool addedVerse)
        {
            string    returnString = string.Empty;
            BCVSTRUCT BCVNew       = new BCVSTRUCT()
            {
                Book = BCVCurrent.Book
            };

            if (stringToParse.Contains(CV_SEPARATOR.ToString()))//only the book is shared; it contains its own chapter and verse
            {
                BCVNew.Chapter = stringToParse.Remove(stringToParse.IndexOf(CV_SEPARATOR));
                BCVNew.Verse   = stringToParse.Remove(0, stringToParse.IndexOf(CV_SEPARATOR) + 1);
                returnString   = BCVNew.Book + BCVNew.Chapter + CV_SEPARATOR + BCVNew.Verse;
            }
            else
            {
                if (BCVCurrent.Verse == null || BCVCurrent.Verse.Length < 1)//only chapter is recorded, so the string represents a chapter as well
                {
                    BCVNew.Chapter = stringToParse;
                    returnString   = BCVNew.Book + BCVNew.Chapter;
                }
                else
                {
                    if (addedVerse)//only the book is shared e.g. PSA140,141
                    {
                        BCVNew.Chapter = stringToParse;
                        returnString   = BCVNew.Book + BCVNew.Chapter;
                    }
                    else//both book and chapter are shared e.g. HEB11:1,6
                    {
                        BCVNew.Chapter = BCVCurrent.Chapter;
                        BCVNew.Verse   = stringToParse;
                        returnString   = BCVNew.Book + BCVNew.Chapter + CV_SEPARATOR + BCVNew.Verse;
                    }
                }
            }
            return(returnString);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Gets verse text for the given range.
 /// </summary>
 /// <param name="start">The beginning of the range.</param>
 /// <param name="end">The end of the range (values optional).</param>
 /// <returns></returns>
 public static List <string> GetVerseText(ref BCVSTRUCT start, ref BCVSTRUCT end)
 {
     if (end.Book == null)//No range; get single verse
     {
         return(new List <string>()
         {
             GetSingleVerse(start)
         });
     }
     else//There is a range i.e. both start and end are known
     {
         bool startFound = false, endFound = false;
         foreach (XmlElement BOOKsample in KJVBibleNode.ChildNodes)
         {
             if (BOOKsample.Attributes["NAME"].Value == start.Book)
             {
                 startFound = true;
             }
             if (BOOKsample.Attributes["NAME"].Value == end.Book)
             {
                 endFound = true;
             }
             if (endFound)
             {
                 if (startFound)
                 {
                     return(GetMultipleVerses(start, end));
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
         return(null);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Get multiple verses from the a range of chapters of a book.
 /// </summary>
 /// <param name="book">The common book.</param>
 /// <param name="start">The beginning bcv.</param>
 /// <param name="end">The ending bcv.</param>
 /// <returns>List of verse texts.</returns>
 private static List <string> GetMultipleVersesSameBook(string book, BCVSTRUCT start, BCVSTRUCT end)
 {
     foreach (XmlNode BOOKSample in KJVBibleNode.ChildNodes)
     {
         XmlNode BOOK = BOOKSample;
         if (BOOK.Attributes["NAME"].Value == book)
         {
             List <string> list = new List <string>();
             int           ch1 = int.Parse(start.Chapter) - 1, ch2 = int.Parse(end.Chapter) - 1;
             int           v1, v2;
             for (int j = ch1; j <= ch2; j++)
             {
                 var CHAPTER = BOOK.ChildNodes[j];
                 if (j == ch1)//read the first chapter from the specified verse to the end
                 {
                     v1 = int.Parse(start.Verse);
                     v2 = VerseCount(start.Book, start.Chapter);
                 }
                 else if (j == ch2)//read the last chapter from the beginning to the specified verse
                 {
                     v1 = 1;
                     v2 = int.Parse(end.Verse);
                 }
                 else//read the chapter from the beginning to the end
                 {
                     v1 = 1;
                     v2 = VerseCount(start.Book, (j + 1).ToString());
                 }
                 list.AddRange(GetMultipleVersesSameBookSameChapter(book, j, v1 - 1, v2 - 1));
                 CHAPTER = CHAPTER.NextSibling;
             }
             return(list);
         }
     }
     return(null);
 }
Exemplo n.º 12
0
        private static void GetEnd(string stringToParse, BCVSTRUCT bibleText_Start, ref BCVSTRUCT bibleText_End)
        {
            if (!string.IsNullOrWhiteSpace(stringToParse) && stringToParse.Length > 0)
            {
                bool chapterFound = false;

                if (stringToParse.Length >= 2)
                {
                    if (char.IsDigit(stringToParse[0]) && char.IsLetter(stringToParse[1]))//e.g 2John1:1-3John1:1
                    {
                        bibleText_End.Book += stringToParse[0];
                    }
                }
                foreach (char c in stringToParse)
                {
                    if (char.IsLetter(c))//e.g Hebrews11:1-Hebrews12:1 or the rest of 2John1:1-3John1:1 if the preceding conditions were met
                    {
                        bibleText_End.Book += c;
                        stringToParse       = stringToParse.Remove(0, stringToParse.IndexOf(c) + 1);
                    }
                }

                if (string.IsNullOrWhiteSpace(bibleText_End.Book))//e.g Hebrews11:1-12:1 End.Book should be Hebrews as well
                {
                    bibleText_End.Book = bibleText_Start.Book;
                }

                foreach (char c in stringToParse)
                {
                    if (char.IsPunctuation(c) && c == ':')//e.g Hebrews11:1-12:1
                    {
                        chapterFound = true;
                    }
                }
                if (chapterFound)//e.g Hebrews11:1-12:1 chapter is 12
                {
                    bibleText_End.Chapter = stringToParse.Remove(stringToParse.IndexOf(':'));
                    stringToParse         = stringToParse.Remove(0, stringToParse.IndexOf(':') + 1);
                }
                else//e.g Hebrews11:1-12 or //e.g Hebrews11-12
                {
                    if (bibleText_Start.Verse == null)//e.g Hebrews11-12
                    {
                        foreach (char c in stringToParse)
                        {
                            bibleText_End.Chapter += c;
                            stringToParse          = stringToParse.Remove(0, stringToParse.IndexOf(c) + 1);
                        }
                    }
                    else//e.g Hebrews11:1-12 chapter should be 11 as well i.e Hebrews 11:12 for End
                    {
                        bibleText_End.Chapter = bibleText_Start.Chapter;
                    }
                }

                foreach (char c in stringToParse)
                {
                    if (bibleText_Start.Verse == null)
                    {
                        bibleText_End.Chapter += c;
                    }
                    else
                    {
                        bibleText_End.Verse += c;
                    }
                }
            }
        }
Exemplo n.º 13
0
        private static BCVSTRUCT ParseString2(string stringToParse, List <BCVRANGE> listOfBCVRanges, out bool addedVerse)
        {
            BCVSTRUCT bibleText_Start = new BCVSTRUCT()
            {
                bcv     = null,
                Book    = null,
                Chapter = null,
                Verse   = null
            };
            BCVSTRUCT bibleText_End = new BCVSTRUCT()
            {
                bcv     = null,
                Book    = null,
                Chapter = null,
                Verse   = null
            };

            addedVerse = false;

            if (new Regex(regexBCVrBCV).IsMatch(stringToParse))
            {
                int separatorIndex = stringToParse.IndexOf(RANGE_SEPARATOR);

                string start = stringToParse.Remove(separatorIndex);
                bibleText_Start      = StringToBCV(start);
                bibleText_Start.Book = ConfirmBibleBookName(bibleText_Start.Book);
                addedVerse           = false;

                string end = stringToParse.Substring(separatorIndex + 1);
                bibleText_End      = StringToBCV(end);
                bibleText_End.Book = ConfirmBibleBookName(bibleText_End.Book);
            }
            else if (new Regex(regexBCrBC).IsMatch(stringToParse))
            {
                int separatorIndex = stringToParse.IndexOf(RANGE_SEPARATOR);

                string start = stringToParse.Remove(separatorIndex);
                bibleText_Start       = StringToBCV(start);
                bibleText_Start.Book  = ConfirmBibleBookName(bibleText_Start.Book);
                bibleText_Start.Verse = "1";
                addedVerse            = true;

                string end = stringToParse.Substring(separatorIndex + 1);
                bibleText_End       = StringToBCV(end);
                bibleText_End.Book  = ConfirmBibleBookName(bibleText_End.Book);
                bibleText_End.Verse = VerseCount(bibleText_End.Book, bibleText_End.Chapter).ToString();
            }
            else if (new Regex(regexBCVrCV).IsMatch(stringToParse))
            {
                int separatorIndex = stringToParse.IndexOf(RANGE_SEPARATOR);

                string start = stringToParse.Remove(separatorIndex);
                bibleText_Start      = StringToBCV(start);
                bibleText_Start.Book = ConfirmBibleBookName(bibleText_Start.Book);
                addedVerse           = false;

                string end = bibleText_Start.Book + stringToParse.Substring(separatorIndex + 1);
                bibleText_End      = StringToBCV(end);
                bibleText_End.Book = ConfirmBibleBookName(bibleText_End.Book);
            }
            else if (new Regex(regexBCrC).IsMatch(stringToParse))
            {
                int separatorIndex = stringToParse.IndexOf(RANGE_SEPARATOR);

                string start = stringToParse.Remove(separatorIndex);
                bibleText_Start       = StringToBCV(start);
                bibleText_Start.Book  = ConfirmBibleBookName(bibleText_Start.Book);
                bibleText_Start.Verse = "1";
                addedVerse            = true;

                string end = bibleText_Start.Book + stringToParse.Substring(separatorIndex + 1);
                bibleText_End       = StringToBCV(end);
                bibleText_End.Book  = ConfirmBibleBookName(bibleText_End.Book);
                bibleText_End.Verse = VerseCount(bibleText_End.Book, bibleText_End.Chapter).ToString();
            }
            else if (new Regex(regexBCVrV).IsMatch(stringToParse))
            {
                int separatorIndex = stringToParse.IndexOf(RANGE_SEPARATOR);

                string start = stringToParse.Remove(separatorIndex);
                bibleText_Start      = StringToBCV(start);
                bibleText_Start.Book = ConfirmBibleBookName(bibleText_Start.Book);
                addedVerse           = false;

                string end = bibleText_Start.Book + bibleText_Start.Chapter + CV_SEPARATOR + stringToParse.Substring(separatorIndex + 1);
                bibleText_End      = StringToBCV(end);
                bibleText_End.Book = ConfirmBibleBookName(bibleText_End.Book);
            }
            else if (new Regex(regexBCV).IsMatch(stringToParse))
            {
                bibleText_Start      = StringToBCV(stringToParse);
                bibleText_Start.Book = ConfirmBibleBookName(bibleText_Start.Book);
                addedVerse           = false;
            }
            else if (new Regex(regexBC).IsMatch(stringToParse))
            {
                bibleText_Start       = StringToBCV(stringToParse);
                bibleText_Start.Book  = ConfirmBibleBookName(bibleText_Start.Book);
                bibleText_Start.Verse = "1";
                addedVerse            = true;

                bibleText_End.Book    = bibleText_Start.Book;
                bibleText_End.Chapter = bibleText_Start.Chapter;
                bibleText_End.Verse   = VerseCount(bibleText_End.Book, bibleText_End.Chapter).ToString();
            }
            bibleText_Start.bcv = GenerateBCVString(bibleText_Start);
            bibleText_End.bcv   = GenerateBCVString(bibleText_End);

            BCVRANGE range = new BCVRANGE()
            {
                Start = bibleText_Start,
                End   = bibleText_End
            };

            if (bibleText_Start.Book != null)
            {
                listOfBCVRanges.Add(range);
            }

            if (bibleText_End.Book != null)
            {
                return(bibleText_End);
            }
            else if (bibleText_Start.Book != null)
            {
                return(bibleText_Start);
            }
            else
            {
                return(new BCVSTRUCT()
                {
                    bcv = null,
                    Book = null,
                    Chapter = null,
                    Verse = null
                });
            }
        }