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

ProcessToken() private method

If the token starts a typographic paragraph, store it as a paragraph-start token and highlight (shows up on user interface) its text. Otherwise, if the token is a quotation mark (either opening or closing, as defined by the quotation categorizer), store it as a quotation mark token.
private ProcessToken ( ITextToken tok, SILUBS.ScriptureChecks.VerseTextToken verseTok ) : void
tok ITextToken The token being processed
verseTok SILUBS.ScriptureChecks.VerseTextToken
return void
		internal void ProcessToken(ITextToken tok, VerseTextToken verseTok)
		{
			if (tok == null)
				throw new ArgumentNullException("tok");

			Debug.Assert(!(tok is VerseTextToken));

			if (tok.IsParagraphStart)
			{
				TextTokenSubstring tts = new TextTokenSubstring(tok, 0, 0);
				ParaStartToken pstok = new ParaStartToken(tts, tok.ParaStyleName);
				m_quotationRelatedTokens.Add(pstok);
			}

			AddTextToParaStartTokens(tok);

			// Find the first non whitespace, non quotation mark character in the token's
			// text. This will be used in the following loop to determine what quotation
			// marks precede all other characters in the token (i.e. what quotation marks
			// begin the paragraph and are possible continuers).
			Match match = m_regExNonQuotes.Match(tok.Text);
			int iFirstNoneQMarkChar = (match.Success ? match.Index : -1);

			// Now find all the quotation marks in the token's text.
			MatchCollection mc = m_regExQuotes.Matches(tok.Text);

			// Go through all the quotation marks found, creating quotation tokens
			// for each.
			foreach (Match m in mc)
			{
				TextTokenSubstring tts = new TextTokenSubstring(tok, m.Index, m.Length);

				bool fIsParaStart = verseTok != null ? verseTok.IsParagraphStart : tok.IsParagraphStart;
				bool fIsOpener = m_qmCategorizer.IsInitialPunctuation(tts.Text);
				bool fPossibleContinuer = (m.Index < iFirstNoneQMarkChar && fIsParaStart);
				QuotationMarkToken qmt = new QuotationMarkToken(tts, m_qmCategorizer,
					fIsOpener, fPossibleContinuer);
				m_quotationRelatedTokens.Add(qmt);
			}
		}

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;
		}