Example #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Compares the current instance with another object of the same type.
		/// </summary>
		/// <param name="obj">An object to compare with this instance.</param>
		/// <returns>
		/// A 32-bit signed integer that indicates the relative order of the objects being 
		/// compared. The return value has these meanings: 
		/// 
		/// Value				Meaning 
		/// Less than zero		This instance is less than <paramref name="obj"/>. 
		/// Zero				This instance is equal to <paramref name="obj"/>. 
		/// Greater than zero	This instance is greater than <paramref name="obj"/>.
		/// </returns>
		/// <exception cref="T:System.ArgumentException">
		/// 	<paramref name="obj"/> is not the same type as this instance. </exception>
		/// ------------------------------------------------------------------------------------
		public override int CompareTo(object obj)
		{
			if (obj == null)
				throw new ArgumentException();

			ScrReference right;
			if (obj is ScrReference)
			{
				right = (ScrReference)obj;

				// If versifications don't match, make a new one, converted to correct versification
				if (m_versification != right.m_versification &&
					m_versification != ScrVers.Unknown &&
					right.m_versification != ScrVers.Unknown)
				{
					// Neither of the versifications involved are unknown, so do a normal conversion
					right = new ScrReference(right, m_versification);
				}
				else if (m_versification != right.m_versification)
				{
					// one of the versifications involved is unknown, so just treat it as the same
					// versification as the known one.
					if (right.m_versification != ScrVers.Unknown)
					{
						ScrReference newThis = new ScrReference(BBCCCVVV, right.m_versification);
						return newThis.CompareTo(right);
					}

					right = new ScrReference(right.BBCCCVVV, m_versification);
				}
			}
			else if (obj is BCVRef)
				right = new ScrReference((BCVRef)obj, m_versification);
			else if (obj is int)
				right = new ScrReference((int)obj, m_versification);
			else
				throw new ArgumentException();

			return base.CompareTo(right);
		}
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Copy a reference
		/// </summary>
		/// <param name="from">The ScrReference to copy.</param>
		/// ------------------------------------------------------------------------------------
		public ScrReference(ScrReference from)
			: this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification)
		{
		}
Example #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the total number of chapters from the specified start ref to the end reference.
		/// </summary>
		/// <remarks>Note: This is based on the total number of chapters for the current
		/// versification.  If there are some chapters missing in a book present those will 
		/// not be accounted for.</remarks>
		/// <param name="booksPresent">a bool array indicating the presence of each book.</param>
		/// <param name="refStart">Scripture reference where importing begins.</param>
		/// <param name="refEnd">Scripture reference where importing ends.</param>
		/// <returns>The total number of chapters between the start and end references
		/// (inclusively) in books that are present.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static int GetNumberOfChaptersInRange(List<int> booksPresent, ScrReference refStart,
			ScrReference refEnd)
		{
			Debug.Assert(refStart.Versification == refEnd.Versification);

			// Determine which chapter number to use in the start reference
			int startChapter = (refStart.Chapter == 0) ? 1 : refStart.Chapter;

			// Consider the case where the start and end references are in the same book.
			if (refStart.Book == refEnd.Book)
				return booksPresent.Contains(refStart.Book) ? refEnd.Chapter - startChapter + 1 : 0;

			// Add up the number of chapters for the books from the start to the end.
			int expectedChapters = 0;
			for (int book = refStart.Book; book <= refEnd.Book; book++)
			{
				if (booksPresent.Contains(book))
				{
					ScrReference scRef = new ScrReference(book, 1, 1, refStart.Versification);
					if (book == refStart.Book)
						expectedChapters += refStart.LastChapter - startChapter + 1;
					else if (book == refEnd.Book)
						expectedChapters += refEnd.Chapter;
					else
						expectedChapters += scRef.LastChapter;
				}
			}

			return expectedChapters;
		}
Example #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Parses the given string representing the reference range.
		/// </summary>
		/// <param name="sRefRng">The string representing the reference range.</param>
		/// <param name="bcvRefStart">The start reference (passed by ref because we use it to
		/// infer any components of the reference that are misisng in sRefRng).</param>
		/// <param name="bcvRefEnd">The end reference.</param>
		/// <param name="versification">The versification.</param>
		/// <returns>
		/// 	<c>true</c> if successfully parsed; <c>false</c> otherwise
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static bool ParseRefRange(string sRefRng, ref BCVRef bcvRefStart,
			ref BCVRef bcvRefEnd, ScrVers versification)
		{
			if (string.IsNullOrEmpty(sRefRng))
				return false;

			if (!sRefRng.Contains("--"))
				return BCVRef.ParseRefRange(sRefRng, ref bcvRefStart, ref bcvRefEnd, false);

			sRefRng = sRefRng.Trim();
			string[] pieces = sRefRng.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries);
			if (pieces.Length != 2)
				return false;

			string sFirstRef = pieces[0];
			int bbcccvvvStart = bcvRefStart.BBCCCVVV;
			bcvRefStart.Parse(sFirstRef);
			if (!bcvRefStart.Valid)
			{
				bcvRefStart.BBCCCVVV = bbcccvvvStart;
				return false;
			}
			string sEndRef = pieces[1];
			int chapter;
			if (Int32.TryParse(sEndRef, out chapter))
			{
				ScrReference scrRefEnd = new ScrReference(bcvRefStart.Book, chapter, 1, versification);
				scrRefEnd.Verse = scrRefEnd.LastVerse;
				bcvRefEnd.BBCCCVVV = scrRefEnd.BBCCCVVV;
				return true;
			}

			return false;
		}
Example #5
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);
		}