SILUBS.ScriptureChecks.QTokenProcessor.FinalizeResult C# (CSharp) Method

FinalizeResult() private method

Goes through the list of quotation related tokens and generates errors for missing continuers and quotations.
private FinalizeResult ( ) : void
return void
		internal void FinalizeResult()
		{
			if (m_quotationRelatedTokens.Count == 0)
				return;

			OpenQuotes openQuotes = new OpenQuotes();
			string prevStyleName = string.Empty;
			for (int i = 0; i < m_quotationRelatedTokens.Count; i++)
			{
				QToken qrtok = m_quotationRelatedTokens[i];
				if (qrtok is QuotationMarkToken)
				{
					QuotationMarkToken qt = (QuotationMarkToken)qrtok;
					CheckQuote(qt, openQuotes);
					openQuotes.MostRecent = qt;
					m_fFoundMissingContinuer = false;
				}
				else if (qrtok is ParaStartToken)
				{
					ParaStartToken pstok = qrtok as ParaStartToken;
					List<string> continuersExpected =
						GetContinuersNeeded(pstok.StyleName, prevStyleName, openQuotes.Level);

					prevStyleName = pstok.StyleName;

					if (continuersExpected.Count > 0)
					{
						if (MatchContinuers(i, continuersExpected, openQuotes.Level))
						{
							i += continuersExpected.Count;
						}
						else
						{
							int contLevel = GetExpectedContinuerLevel(
								continuersExpected[continuersExpected.Count - 1], openQuotes.Level);
							ReportError(pstok, string.Format(continuersExpected.Count == 1 ?
								Localize("Missing continuation mark: level {0}") :
								Localize("Missing continuation marks: levels 1-{0}"),
								contLevel));

							m_fFoundMissingContinuer = true;
						}
					}
				}
			}

			CheckForRemaining(openQuotes);
			m_quotationRelatedTokens.Clear();
		}

Usage Example

Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets a list if TextTokenSubstrings containing the references and character offsets
		/// where quotation problems occur.
		/// </summary>
		/// <param name="tokens">The tokens (from the data source) to check for quotation problems.</param>
		/// <param name="desiredKey">empty string.</param>
		/// ------------------------------------------------------------------------------------
		public List<TextTokenSubstring> GetReferences(IEnumerable<ITextToken> tokens, string desiredKey)
		{
			m_charCategorizer = m_chkDataSource.CharacterCategorizer;
			ValidItems = m_chkDataSource.GetParameterValue(m_validItemsParameter);
			InvalidItems = m_chkDataSource.GetParameterValue(m_invalidItemsParameter);

			QuotationMarkCategorizer qmCategorizer = new QuotationMarkCategorizer(m_chkDataSource);
			m_qmProblems = new List<TextTokenSubstring>();

			QTokenProcessor bodyProcessor =	new QTokenProcessor(m_chkDataSource,
				m_charCategorizer, qmCategorizer, desiredKey, m_qmProblems);

			QTokenProcessor noteProcessor =	new QTokenProcessor(m_chkDataSource,
				m_charCategorizer, qmCategorizer, desiredKey, m_qmProblems);

			VerseTextToken scrToken = new VerseTextToken();
			foreach (ITextToken tok in tokens)
			{
				if (tok.TextType == TextType.Note)
				{
					// If a new note is starting finalize any sequences from the previous note.
					if (tok.IsNoteStart)
						noteProcessor.FinalizeResult();
					noteProcessor.ProcessToken(tok, null);
				}
				else if (tok.TextType == TextType.Verse || tok.TextType == TextType.Other ||
					tok.IsParagraphStart)
				{
					scrToken.Token = tok;
					// body text: finalize any note that was in progress and continue with body text
					noteProcessor.FinalizeResult();
					bodyProcessor.ProcessToken(tok, scrToken);
				}
			}

			noteProcessor.FinalizeResult();
			bodyProcessor.FinalizeResult();
			return m_qmProblems;
		}