Exemplo n.º 1
0
        private IList <VerseItem> TryGetChapters(string book, string text)
        {
            var items  = new List <VerseItem>();
            var groups = this.chapterRegex.Match(text).Groups;

            ExceptionUtilities.ThrowInvalidOperationExceptionIfFalse(groups.Count >= 4, "At least 4 groups.");
            ExceptionUtilities.ThrowInvalidOperationExceptionIfFalse(groups[1].Captures.Count == 1, "Must 1 capture.");
            var last = groups[1].Captures[0].Value;
            var loop = 0;

            while (loop < groups[2].Captures.Count)
            {
                var capture2   = groups[2].Captures[loop].Value;
                var capture3   = groups[3].Captures[loop].Value;
                var difference = capture2.Substring(0, capture2.Length - capture3.Length).Trim();
                if (this.chapterConnectors.Contains(difference))
                {
                    var item = new VerseItem
                    {
                        Book  = book,
                        Verse = this.MapChapter(last) + ":1-" + this.MapChapter(capture3) + ":999",
                    };
                    items.Add(item);
                    loop++;
                    if (loop < groups[2].Captures.Count)
                    {
                        last = groups[3].Captures[loop].Value;
                    }
                    loop++;
                }
                else
                {
                    var item = new VerseItem
                    {
                        Book  = book,
                        Verse = this.MapChapter(last) + ":1-999",
                    };
                    items.Add(item);
                    last = capture3;
                    loop++;
                }
            }

            if (loop == groups[2].Captures.Count)
            {
                var item = new VerseItem
                {
                    Book  = book,
                    Verse = this.MapChapter(last) + ":1-999",
                };
                items.Add(item);
            }

            return(items);
        }
Exemplo n.º 2
0
        public IList <VerseItem> GetVerses(Match match)
        {
            ExceptionUtilities.ThrowArgumentNullExceptionIfNull(match, nameof(match));

            var book   = match.Groups[1].Value.Trim();
            var verses = match.Groups[2].Value;

            if (!this.verseRegex.IsMatch(verses))
            {
                return(this.TryGetChapters(book, verses));
            }

            var items  = new List <VerseItem>();
            var groups = verses.Replace(" ", string.Empty).Split(this.groupSeparators.ToCharArray());
            var chapterSeparatorSet = new HashSet <char>(this.chapterSeparators.ToArray());

            foreach (var group in groups)
            {
                if (group.Count(chapterSeparatorSet.Contains) > 1)
                {
                    var item = new VerseItem
                    {
                        Book  = book,
                        Verse = group,
                    };
                    items.Add(item);
                }
                else
                {
                    var parts    = group.Split(chapterSeparatorSet.ToArray());
                    var chapter  = parts[0];
                    var sections = parts[1].Split(this.verseSeparators.ToCharArray());
                    foreach (var section in sections)
                    {
                        var item = new VerseItem
                        {
                            Book  = book,
                            Verse = chapter + ":" + section,
                        };
                        items.Add(item);
                    }
                }
            }

            return(items);
        }