Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the book name for a given book number.
        /// </summary>
        /// <param name="nBook">one-based index of the book (Genesis = 1).</param>
        /// <returns>The book name as a string.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual string GetBookName(int nBook)
        {
            WsNames wsNames = GetWsNames(PrimaryEncoding);

            Debug.Assert(nBook > 0 && nBook <= wsNames.Name.Length);
            return(wsNames.Name[nBook - 1]);
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Parses the user typed in string. Creates and returns a ScrReference object.
        /// </summary>
        /// <param name="sTextToBeParsed">Reference string the user types in.</param>
        /// <param name="startingBook">The 0-based index of starting book to consider when
        /// parsing reference.</param>
        /// <returns>The generated scReference object.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual ScrReference ParseRefString(string sTextToBeParsed, int startingBook)
        {
            Regex regex = new Regex(@"(?<book>\w?.*[a-zA-Z])\s?((?<chapter>\d+)(\D+(?<verse>\d+))?)?");
            Match match = regex.Match(sTextToBeParsed.TrimStart());

            if (match.Success)
            {
                // Determine book number
                int    nBookNumber = 0;
                string bookToken   = match.Groups["book"].Value;
                foreach (int nEnc in m_requestedEncodings)
                {
                    WsNames wsNames = GetWsNames(nEnc);
                    if (wsNames != null)
                    {
                        nBookNumber = wsNames.Search(bookToken, startingBook);
                        if (nBookNumber > 0)
                        {
                            break;
                        }
                    }
                }

                // Break out the chapter and verse numbers
                int chapter;
                if (!int.TryParse(match.Groups["chapter"].Value, out chapter))
                {
                    chapter = 1;                        // it's legal to specify 0 as chapter number (i.e. intro material)
                }
                int verse;
                int.TryParse(match.Groups["verse"].Value, out verse);

                // If there was no verse specified, then make it 1
                if (verse == 0)
                {
                    verse = 1;
                }

                // If the book number is invalid...
                if (nBookNumber < 1 || nBookNumber > 66)
                {
                    // just set the reference to GEN 1:1
                    nBookNumber = 1;
                    chapter     = 1;
                    verse       = 1;
                }
                return(new ScrReference(nBookNumber, chapter, verse,
                                        m_versificationProvider.Versification));
            }
            return(new ScrReference());
        }