Exemplo n.º 1
0
 public SectionParseResult(SectionSpec sectionSpec, IEnumerable <ParseError> errors)
 {
     SectionSpec = sectionSpec;
     if (errors != null)
     {
         Errors = errors.ToArray();
     }
 }
Exemplo n.º 2
0
 public void ValidateSectionSpec(string text, SectionSpec spec,
                                 List <ParseError> errors)
 {
     if (spec.Start.BookIndex > spec.End.BookIndex ||
         (spec.Start.BookIndex == spec.End.BookIndex &&
          spec.Start.ChapterNumber > spec.End.ChapterIndex))
     {
         errors.Add(new ParseError(text, "Start and end in wrong order"));
     }
 }
Exemplo n.º 3
0
        public SectionParseResult ParseSection(string text)
        {
            List <ParseError> errors = new List <ParseError>();
            SectionSpec       spec   = null;

            if (text.Contains("-"))
            {
                string[] pieces = text.Split("-");
                if (pieces.Length > 2)
                {
                    errors.Add(new ParseError(text, "Too many dashes"));
                }
                if (Regex.IsMatch(pieces[1], @"[^\d\s]"))
                {
                    // two separate books
                    BookAndChapterSpec start = ParseBookAndChapter(pieces[0],
                                                                   EndpointType.Start, errors);
                    BookAndChapterSpec end = ParseBookAndChapter(pieces[1],
                                                                 EndpointType.End, errors);
                    if (start != null && end != null)
                    {
                        spec = new SectionSpec(start, end);
                    }
                }
                else if (pieces.Length == 2)
                {
                    // single book range
                    spec = ParseSingleBookRange(text, errors);
                }
            }
            else
            {
                if (Regex.IsMatch(text, @"\d\s*$"))
                {
                    BookAndChapterSpec start = ParseBookAndChapter(text, EndpointType.Start, errors);
                    spec = new SectionSpec(start, start);
                }
                else
                {
                    BookSpec book = ParseBook(text, errors);
                    if (book != null)
                    {
                        BookAndChapterSpec start = new BookAndChapterSpec(this, book.Names[0], 1);
                        BookAndChapterSpec end   = new BookAndChapterSpec(this, book.Names[0], book.ChapterCount);
                        spec = new SectionSpec(start, end);
                    }
                }
            }
            if (spec != null)
            {
                ValidateSectionSpec(text, spec, errors);
            }
            if (errors.Count > 0)
            {
                return(new SectionParseResult(null, errors));
            }
            else
            {
                return(new SectionParseResult(spec, errors));
            }
        }