예제 #1
0
        internal static Range Create(ScriptureInfo scriptureInfo, Data.RawRange range, int offset, RepositoryMode mode)
        {
            Range result = new Range();

            result._scriptureInfo = scriptureInfo;
            result.Offset         = offset;

            result.Start = Verse.Create(scriptureInfo, range.FirstBook, range.FirstChapter, range.FirstVerse, range.FirstVerseSuffix, VersePosition.First, mode);
            result.End   = Verse.Create(scriptureInfo, range.SecondBook, range.SecondChapter, range.SecondVerse, range.SecondVerseSuffix, VersePosition.Last, mode);

            int firstChapterLimitsOffset = 1 - result.Start.VerseNumber;

            result._offsetChapterLimits =
                OffsetChapterLimits.Create(
                    firstChapterLimitsOffset,
                    scriptureInfo.ChapterLimits.Where(c => result.Start <= c && c <= result.End)
                    );

            result.Length =
                result._offsetChapterLimits.Select(c => c.ChapterLimits).Sum(c => c.EndVerseNumber)
                + firstChapterLimitsOffset
                - (result._offsetChapterLimits.Last().ChapterLimits.EndVerseNumber - result.End.VerseNumber);

            if (mode != RepositoryMode.Optimistic && (result.Start == null || result.End == null))
            {
                result = null;
            }

            return(result);
        }
예제 #2
0
        public Verse this[int index]
        {
            get
            {
                if (index < 0 || index >= this.Length)
                {
                    throw new IndexOutOfRangeException("index is greater than or equal to the length of this object or less than zero.");
                }

                // TODO: perfomance tune this line for large ranges
                var c = this._offsetChapterLimits.Last(x => x.Offset <= index);

                var bi = _scriptureInfo.GetBookInfo(c.ChapterLimits.BookNumber);

                Verse verse = Verse.Create(_scriptureInfo, bi, c.ChapterLimits.ChapterNumber, index - c.Offset + 1, null, VersePosition.First, RepositoryMode.Safe);

                return(verse);
            }
        }
예제 #3
0
        /// <summary>
        /// Converts the value of a specified object to an equivalent string representation using specified format and culture-specific formatting information.
        /// </summary>
        /// <param name="format">A format string containing formatting specifications.</param>
        /// <param name="arg">An object to format.</param>
        /// <param name="formatProvider">An object that supplies format information about the current instance.</param>
        /// <returns>
        /// The string representation of the value of <paramref name="arg"/>, formatted as specified by <paramref name="format"/> and <paramref name="formatProvider"/>.
        /// </returns>
        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            StringBuilder sb = new StringBuilder();

            Verse verse = (Verse)arg;

            if (format == null)
            {
                format = DefaultFormat;
            }

            for (int i = 0; i < format.Length; i++)
            {
                if (i < format.Length && format[i] == '\\')
                {
                    sb.Append(format[i + 1]);
                    i += 1;                                                                                         // charater is escaped
                }
                else if (i + 2 < format.Length && format[i] == 'B' && format[i + 1] == 'B' && format[i + 2] == 'B') // BBB - Capitalized name of book
                {
                    sb.Append(verse.BookName);
                    i += 2;
                }
                else if (i + 1 < format.Length && format[i] == 'B' && format[i + 1] == 'B') // BB - Capitalized long abbreviation of book
                {
                    sb.Append(verse.LongBookAbbreviation);
                    i += 1;
                }
                else if (format[i] == 'B') // B - Capitalized short abbreviation of book
                {
                    sb.Append(verse.ShortBookAbbreviation);
                }
                else if (i + 2 < format.Length && format[i] == 'b' && format[i + 1] == 'b' && format[i + 2] == 'b') // bbb - Lower case name of book
                {
                    sb.Append(verse.BookName.ToLower());
                    i += 2;
                }
                else if (i + 1 < format.Length && format[i] == 'b' && format[i + 1] == 'b') // bb - Lower case long abbreviation of book
                {
                    sb.Append(verse.LongBookAbbreviation.ToLower());
                    i += 1;
                }
                else if (format[i] == 'b') // b - Lower case short abbreviation of book
                {
                    sb.Append(verse.ShortBookAbbreviation.ToLower());
                }
                else if (format[i] == 'c') // c - Chapter number
                {
                    sb.Append(verse.ChapterNumber);
                }
                else if (format[i] == 'v') // v - Verse number
                {
                    sb.Append(verse.VerseNumber);
                }
                else if (format[i] == 's') // s - Verse suffix
                {
                    sb.Append(verse.Suffix);
                }
                else if (format[i] == 'n') // n - Name of scripture
                {
                    sb.Append(verse.ScriptureName);
                }
                else if (i + 1 < format.Length && format[i] == 't' && format[i + 1] == 't') // tt - Name of scripture translation
                {
                    sb.Append(verse.TranslationName);
                    i += 1;
                }
                else if (format[i] == 't') // t - Lowercase translation of scripture translation
                {
                    sb.Append(verse.TranslationAbbreviation.ToLower());
                }
                else if (format[i] == 'T') // T - Uppercase translation of scripture translation
                {
                    sb.Append(verse.TranslationAbbreviation.ToUpper());
                }
                else
                {
                    sb.Append(format[i]);
                }
            }

            return(sb.ToString());
        }