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