public static int CountTextUnit(TextUnit tu, TextPatternRange rangeToCount)
{
ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null"); // Sanity check
TextPatternRange clone = rangeToCount.Clone();
int count = clone.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, tu, Int32.MaxValue);
// Provider / Text Unit specific offsets
switch(typeOfProvider)
{
case "win32":
case "winform":
{
// This is to correct the fact that our line count will skip the last line if it
// DOES NOT have a trailing \r, \n or \r\n
if( tu == TextUnit.Line )
{
string text = rangeToCount.GetText(-1);
AutomationElement element = rangeToCount.GetEnclosingElement();
if( IsTrailingCRLF(element, text) == 0 )
count++;
}
}
break;
case "wpf":
break;
}
return count;
}