SIL.FieldWorks.FDO.FDOTests.FdoTestHelper.ParseSegBaseline C# (CSharp) Method

ParseSegBaseline() private static method

Parses the given segment, calling the correct handler for each word and punctuation token found.
private static ParseSegBaseline ( ISegment seg, int ichBeginOffset, int ichLimOffset, Func handleWord, int>.Action handlePunc, int>.Action handleORC ) : int
seg ISegment The segment.
ichBeginOffset int The index of the character offset relative to the /// paragraph that owns the segment at which the segment begins or should be assumed to /// begin if it doesn't really.
ichLimOffset int The limit (see above).
handleWord Func The delegate to handle each word in the segment.
handlePunc int>.Action The delegate to handle each group of contiguous punctuation /// characters.
handleORC int>.Action The delegate to handle each ORC.
return int
		private static int ParseSegBaseline(ISegment seg, int ichBeginOffset, int ichLimOffset,
			Func<int, string, int, bool> handleWord, Action<string, int> handlePunc,
			Action<int, int> handleORC)
		{
			string baseline = seg.Paragraph.Contents.Text.Substring(ichBeginOffset, ichLimOffset - ichBeginOffset);
			string word = string.Empty;
			string puncForm = string.Empty;
			int iAnalysis = 0, iForm = 0;

			for (int ich = 0; ich < baseline.Length; ich++)
			{
				char ch = baseline[ich];
				if (kPunctuationForms.Contains(ch))
				{
					if (word.Length > 0)
					{
						if (handleWord(iForm++, word, iAnalysis))
							iAnalysis++;
						word = string.Empty;
					}
					puncForm += ch;
				}
				else switch (ch)
				{
					case StringUtils.kChObject:
						// Validate ORC analysis.
						if (word.Length > 0)
						{
							if (handleWord(iForm++, word, iAnalysis))
								iAnalysis++;
							word = string.Empty;
						}
						else if (puncForm.Length > 0)
						{
							handlePunc(puncForm, iAnalysis++);
							puncForm = string.Empty;
							iForm++;
						}
						handleORC(ich, iAnalysis++);
						iForm++;
						break;
					case ' ':
						if (word.Length > 0)
						{
							if (handleWord(iForm++, word, iAnalysis))
								iAnalysis++;
							word = string.Empty;
						}
						else if (puncForm.Length > 0)
						{
							handlePunc(puncForm, iAnalysis++);
							puncForm = string.Empty;
							iForm++;
						}
						break;
					default:
						if (puncForm.Length > 0)
						{
							handlePunc(puncForm, iAnalysis++);
							puncForm = string.Empty;
							iForm++;
						}
						word += ch;
						break;
				}
			}
			if (word.Length > 0)
			{
				if (handleWord(iForm, word, iAnalysis))
					iAnalysis++;
			}
			else if (puncForm.Length > 0)
				handlePunc(puncForm, iAnalysis++);
			return iAnalysis;
		}