// 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); } }
/// ------------------------------------------------------------------------------------ /// <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)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the VersificationTable class for tests. /// </summary> /// ------------------------------------------------------------------------------------ public static void InitializeVersificationTable() { string vrsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); File.WriteAllBytes(Path.Combine(vrsPath, VersificationTable.GetFileNameForVersification(ScrVers.English)), Properties.Resources.eng); File.WriteAllBytes(Path.Combine(vrsPath, VersificationTable.GetFileNameForVersification(ScrVers.Septuagint)), Properties.Resources.lxx); File.WriteAllBytes(Path.Combine(vrsPath, VersificationTable.GetFileNameForVersification(ScrVers.Original)), Properties.Resources.org); VersificationTable.Initialize(vrsPath); }
/// ------------------------------------------------------------------------------------ /// <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]; }
/// ------------------------------------------------------------------------------------ /// <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]); }
// 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(); }
/// ------------------------------------------------------------------------------------ /// <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); } } } }
/// ------------------------------------------------------------------------------------ /// <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; }
/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <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); } } }
// 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); } }
// 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(); }