Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Checks the given tokens for chapter/verse errors and calls the given RecordError
        /// handler for each one.
        /// </summary>
        /// <param name="toks">The tokens to check.</param>
        /// <param name="record">Method to call to record errors.</param>
        /// ------------------------------------------------------------------------------------
        public void Check(IEnumerable <ITextToken> toks, RecordErrorHandler record)
        {
            GetParameters();

            m_recordError = record;
            m_versesFound = new List <int>();
            m_chapTokens.Clear();

            ChapterToken currChapterToken = null;
            VerseToken   currVerseToken   = null;

            foreach (ITextToken token in toks)
            {
                // This token is only necessary when a chapter one is missing
                // and we need a token to use for reporting that it's missing.
                if (m_fallbackToken == null)
                {
                    m_fallbackToken = token;
                }

                if (token.TextType == TextType.ChapterNumber)
                {
                    currChapterToken = new ChapterToken(token, m_chapterNumberFormat);
                    currVerseToken   = null;
                    m_chapTokens.Add(currChapterToken);
                }
                else if (token.TextType == TextType.VerseNumber)
                {
                    if (currChapterToken == null)
                    {
                        //assume chapter one
                        currChapterToken = new ChapterToken(token, 1);
                        m_chapTokens.Add(currChapterToken);
                    }

                    currVerseToken = new VerseToken(token);
                    currChapterToken.VerseTokens.Add(currVerseToken);
                }
                else if (token.TextType == TextType.Verse)
                {
                    if (currChapterToken == null)
                    {
                        // no chapter token and no verse number token
                        // oh no! use verse text token as default, but system
                        // should error on missing verse first.
                        if (currVerseToken == null)
                        {
                            //assume chapter one
                            currChapterToken = new ChapterToken(token, 1);
                            m_chapTokens.Add(currChapterToken);

                            //assume verse one
                            currVerseToken = new VerseToken(token, 1);
                            currChapterToken.VerseTokens.Add(currVerseToken);
                        }
                        // no chapter token, but we have verse number token
                        // then use the verse number token
                        else
                        {
                            // this case should not happen because chapter tokens
                            // are automatically created if a verse number token is
                            // encountered first
                            Debug.Assert(false, "verse number token found without chapter number token");
                        }
                    }
                    else
                    {
                        // we have a chapter token, but no verse number token
                        // use the chapter token as the default token.
                        if (currVerseToken == null)
                        {
                            //assume verse one
                            currVerseToken = new VerseToken(token, 1);
                            currChapterToken.VerseTokens.Add(currVerseToken);
                        }
                        // we have a chapter token, and a verse number token
                        // we are happy
                        else
                        {
                            // do nothing
                        }
                    }
                    currVerseToken.IncrementVerseTextCount(token);
                }
            }

            CheckChapterNumbers();
        }
Пример #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks the given tokens for chapter/verse errors and calls the given RecordError
		/// handler for each one.
		/// </summary>
		/// <param name="toks">The tokens to check.</param>
		/// <param name="record">Method to call to record errors.</param>
		/// ------------------------------------------------------------------------------------
		public void Check(IEnumerable<ITextToken> toks, RecordErrorHandler record)
		{
			GetParameters();

			m_recordError = record;
//			m_versesFound = new List<int>();
			m_chapTokens.Clear();

			ChapterToken currChapterToken = null;
			VerseToken currVerseToken = null;

			foreach (ITextToken token in toks)
			{
				// This token is only necessary when a chapter one is missing
				// and we need a token to use for reporting that it's missing.
				if (m_fallbackToken == null)
					m_fallbackToken = token;

				if (token.TextType == TextType.ChapterNumber)
				{
					currChapterToken = new ChapterToken(token, m_chapterNumberFormat);
					currVerseToken = null;
					m_chapTokens.Add(currChapterToken);
				}
				else if (token.TextType == TextType.VerseNumber)
				{
					if (currChapterToken == null)
					{
						//assume chapter one
						currChapterToken = new ChapterToken(token, 1);
						m_chapTokens.Add(currChapterToken);
					}

					currVerseToken = new VerseToken(token);
					currChapterToken.VerseTokens.Add(currVerseToken);
				}
				else if (token.TextType == TextType.Verse)
				{
					if (currChapterToken == null)
					{
						// no chapter token and no verse number token
						// oh no! use verse text token as default, but system
						// should error on missing verse first.
						if (currVerseToken == null)
						{
							//assume chapter one
							currChapterToken = new ChapterToken( token, 1);
							m_chapTokens.Add(currChapterToken);

							//assume verse one
							currVerseToken = new VerseToken(token, 1);
							currChapterToken.VerseTokens.Add(currVerseToken);
						}
						// no chapter token, but we have verse number token
						// then use the verse number token
						else
						{
							// this case should not happen because chapter tokens
							// are automatically created if a verse number token is
							// encountered first
							Debug.Assert(false, "verse number token found without chapter number token");
						}
					}
					else
					{
						// we have a chapter token, but no verse number token
						// use the chapter token as the default token.
						if (currVerseToken == null)
						{
							//assume verse one
							currVerseToken = new VerseToken(token, 1);
							currChapterToken.VerseTokens.Add(currVerseToken);
						}
						// we have a chapter token, and a verse number token
						// we are happy
						else
						{
							// do nothing
						}
					}
					currVerseToken.IncrementVerseTextCount(token);
				}
			}

			CheckChapterNumbers();
		}