private static void FindMentions(BiteAnalysis biteAnalysis) { string biteText = biteAnalysis.biteText; int startIndex = 0; while ((startIndex = biteText.IndexOf(mentionChar, startIndex)) != -1) { // TODO: insert check if mention is part of email. if (startIndex == biteAnalysis.biteLength - 1) return; int stopIndex = biteText.IndexOfAny(separator, startIndex + 1); int mentionLength; if (IsMention(biteText, startIndex, stopIndex, out mentionLength)) { biteAnalysis.Mentions.Add(biteText.Substring(startIndex + 1, mentionLength)); } // if no stop chars, then we've reached the end if (stopIndex == -1) return; else // If stop chars, the start searching at the stop char for the next @. // The stop char may be an @. startIndex = stopIndex; } }
/// <summary> /// Analyzes the text of a bite and creates a new BiteAnalysis object. /// </summary> /// <param name="biteText"></param> /// <returns></returns> public static BiteAnalysis Create(string biteText) { BiteAnalysis biteAnalysis = new BiteAnalysis(biteText); FindMentions(biteAnalysis); return biteAnalysis; }