示例#1
0
        // Parse lines giving number of verses for each chapter like
        // GEN 1:10 2:23 ...
        private static void ParseMappingLine(string fileName, VersificationTable versification, string line)
        {
            try
            {
                string[] parts       = line.Split('=');
                string[] leftPieces  = parts[0].Trim().Split('-');
                string[] rightPieces = parts[1].Trim().Split('-');

                BCVRef left      = new BCVRef(leftPieces[0]);
                int    leftLimit = leftPieces.GetUpperBound(0) == 0 ? 0 : int.Parse(leftPieces[1]);

                BCVRef right = new BCVRef(rightPieces[0]);

                while (true)
                {
                    versification.toStandard[left.ToString()]    = right.ToString();
                    versification.fromStandard[right.ToString()] = left.ToString();

                    if (left.Verse >= leftLimit)
                    {
                        break;
                    }

                    left.Verse  = left.Verse + 1;
                    right.Verse = right.Verse + 1;
                }
            }
            catch
            {
                // ENHANCE: Make it so the TE version of Localizer can have its own resources for stuff
                // like this.
                throw new Exception("Invalid [" + line + "] " + fileName);
            }
        }
示例#2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructs and returns a new ScrReference representing Revelation 22:21 (or whatver
        /// the last verse is in Revelation for the current default versification scheme).
        /// </summary>
        /// <param name="versification">The versification scheme.</param>
        /// ------------------------------------------------------------------------------------
        public static ScrReference EndOfBible(ScrVers versification)
        {
            VersificationTable versificationTable = VersificationTable.Get(versification);
            int lastChapter = versificationTable.LastChapter(LastBook);

            return(new ScrReference(LastBook, lastChapter,
                                    versificationTable.LastVerse(LastBook, lastChapter), versification));
        }
示例#3
0
 public void GetLastChapterForBook()
 {
     Assert.AreEqual(2, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("HAG")));
     Assert.AreEqual(150, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("PSA")));
     Assert.AreEqual(0, VersificationTable.Get(ScrVers.English).LastChapter(-1));
 }
示例#4
0
 public void GetLastVerseForChapter()
 {
     Assert.AreEqual(20, VersificationTable.Get(ScrVers.English).LastVerse(
                         BCVRef.BookToNumber("PSA"), 9));
     Assert.AreEqual(39, VersificationTable.Get(ScrVers.Septuagint).LastVerse(
                         BCVRef.BookToNumber("PSA"), 9));
     Assert.AreEqual(1, VersificationTable.Get(ScrVers.English).LastVerse(
                         BCVRef.BookToNumber("PSA"), 0), "Intro chapter (0) should be treated as having 1 verse.");
     Assert.AreEqual(0, VersificationTable.Get(ScrVers.Septuagint).LastVerse(0, 0));
 }
示例#5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the versification table for this versification
        /// </summary>
        /// <param name="vers"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static VersificationTable Get(ScrVers vers)
        {
            Debug.Assert(vers != ScrVers.Unknown);

            if (versifications == null)
            {
                versifications = new VersificationTable[versificationFiles.GetUpperBound(0)];
            }

            // Read versification table if not already read
            if (versifications[(int)vers] == null)
            {
                versifications[(int)vers] = new VersificationTable(vers);
                ReadVersificationFile(FileName(vers), versifications[(int)vers]);
            }

            return(versifications[(int)vers]);
        }
示例#6
0
        // Parse lines mapping from this versification to standard versification
        // GEN 1:10	= GEN 2:11
        // GEN 1:10-13 = GEN 2:11-14
        private static void ParseChapterVerseLine(string fileName, VersificationTable versification, string line)
        {
            string[] parts   = line.Split(' ');
            int      bookNum = BCVRef.BookToNumber(parts[0]);

            if (bookNum == -1)
            {
                return;                 // Deuterocanonical books not supported
            }
            if (bookNum == 0)
            {
                throw new Exception("Invalid [" + parts[0] + "] " + fileName);
            }

            while (versification.bookList.Count < bookNum)
            {
                versification.bookList.Add(new int[1] {
                    1
                });
            }

            List <int> verses = new List <int>();

            for (int i = 1; i <= parts.GetUpperBound(0); ++i)
            {
                string[] pieces = parts[i].Split(':');
                int      verseCount;
                if (pieces.GetUpperBound(0) != 1 ||
                    !int.TryParse(pieces[1], out verseCount) || verseCount <= 0)
                {
                    throw new Exception("Invalid [" + line + "] " + fileName);
                }

                verses.Add(verseCount);
            }

            versification.bookList[bookNum - 1] = verses.ToArray();
        }
示例#7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Read versification file and "add" its entries.
        /// At the moment we only do this once. Eventually we will call this twice.
        /// Once for the standard versification, once for custom entries in versification.vrs
        /// file for this project.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="versification"></param>
        /// ------------------------------------------------------------------------------------
        private static void ReadVersificationFile(string fileName, VersificationTable versification)
        {
            using (TextReader reader = new StreamReader(fileName))
            {
                for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
                {
                    line = line.Trim();
                    if (line == "" || line[0] == '#')
                    {
                        continue;
                    }

                    if (line.Contains("="))
                    {
                        ParseMappingLine(fileName, versification, line);
                    }
                    else
                    {
                        ParseChapterVerseLine(fileName, versification, line);
                    }
                }
            }
        }
示例#8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Copy a reference, converting it to the specified versification if necessary
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public ScrReference(ScrReference from, ScrVers targetVersification)
     : this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification)
 {
     VersificationTable.Get(targetVersification).ChangeVersification(this);
 }
示例#9
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Read the versification files into static tables
 /// </summary>
 /// <param name="vrsFolder">Path to the folder containing the .vrs files</param>
 /// <param name="fSupportDeuterocanon">set to <c>true</c> to support deuterocanonical
 /// books, otherwise <c>false</c>.</param>
 /// ------------------------------------------------------------------------------------
 public static void InitializeVersification(string vrsFolder, bool fSupportDeuterocanon)
 {
     VersificationTable.Initialize(vrsFolder);
     SupportDeuterocanon = fSupportDeuterocanon;
 }