SILUBS.ScriptureChecks.ProcessPunctationTokens.IntermediateFinalize C# (CSharp) Method

IntermediateFinalize() private method

Treat each punctuation sequence as a single string, breaking the pattern at each whitespace (Except for whitespace between pairs of quotes that are both in the same direction (both opening or closing quotes).
private IntermediateFinalize ( string desiredKey, List result ) : void
desiredKey string If specified, indicates a specific punctuation pattern to /// seek (all others will be discarded); To retrieve all punctation substrings, specify /// the empty string.
result List List of TextTokenSubstring items that will be added to
return void
		private void IntermediateFinalize(string desiredKey, List<TextTokenSubstring> result)
		{
			// concatanate all the punctuation sequences into one string
			string pattern = "";
			PunctuationToken pTok = null;
			PunctuationToken tok2;

			for (int i = 0; i < m_puncts.Count; ++i)
			{
				tok2 = m_puncts[i];
				pattern += tok2.ToString();

				// Every generated result must start with a punctuation character.
				// If we do not currently have a punctuation character (because it
				// null'ed below) remember this one.
				if (tok2.TokenType == PunctuationTokenType.punctuation || tok2.TokenType == PunctuationTokenType.quoteSeparator)
				{
					Debug.Assert(pTok != null || tok2.TokenType == PunctuationTokenType.punctuation, "Quote separator should never be the first non-whitespace character in a sequence (after all, it IS whitespace!)");
					if (pTok == null)
						pTok = tok2;
					else
					{
						if (tok2.Tts != null && pTok.Tts.LastToken != tok2.Tts.FirstToken)
						{
							Debug.Assert(tok2.Tts.FirstToken == tok2.Tts.LastToken);
							pTok.Tts.AddToken(tok2.Tts.FirstToken);
						}
						pTok.Tts++;
					}
				}

				// Generate a pattern when you see a non-leading whitespace or end of list
				if (tok2.TokenType == PunctuationTokenType.whitespace || i == m_puncts.Count - 1)
				{
					if (pTok != null)  // Must have a punctuation token
					{
						pTok.Tts.InventoryText = pattern;
						if (desiredKey == "" || desiredKey == pTok.Tts.InventoryText)
							result.Add(pTok.Tts);
					}

					// Reset pattern to match this token
					if (tok2.TokenType == PunctuationTokenType.whitespace)
						pattern = tok2.ToString();
					else
						pattern = "";

					pTok = null;
				}
			}
		}