本文整理汇总了C#中ITextProvider.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# ITextProvider.IndexOf方法的具体用法?C# ITextProvider.IndexOf怎么用?C# ITextProvider.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextProvider
的用法示例。
在下文中一共展示了ITextProvider.IndexOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDestructiveChangeForSeparator
private bool IsDestructiveChangeForSeparator(
ISensitiveFragmentSeparatorsInfo separatorInfo,
IEnumerable<IArtifact> itemsInRange,
int start,
int oldLength,
int newLength,
ITextProvider oldText,
ITextProvider newText
) {
if (separatorInfo == null || (separatorInfo.LeftSeparator.Length == 0 && separatorInfo.RightSeparator.Length == 0)) {
return false;
}
// Find out if one of the existing fragments contains position
// and if change damages fragment start or end separators
string leftSeparator = separatorInfo.LeftSeparator;
string rightSeparator = separatorInfo.RightSeparator;
var firstTwoItems = itemsInRange.Take(2).ToList();
var item = firstTwoItems.FirstOrDefault();
// If no items are affected, change is unsafe only if new region contains left side separators.
if (item == null) {
// Simple optimization for whitespace insertion
if (oldLength == 0 && string.IsNullOrWhiteSpace(newText.GetText(new TextRange(start, newLength)))) {
return false;
}
// Take into account that user could have deleted space between existing
// { and % or added { to the existing % so extend search range accordingly.
int fragmentStart = Math.Max(0, start - leftSeparator.Length + 1);
int fragmentEnd = Math.Min(newText.Length, start + newLength + leftSeparator.Length - 1);
return newText.IndexOf(leftSeparator, TextRange.FromBounds(fragmentStart, fragmentEnd), true) >= 0;
}
// Is change completely inside an existing item?
if (firstTwoItems.Count == 1 && (item.Contains(start) && item.Contains(start + oldLength))) {
// Check that change does not affect item left separator
if (TextRange.Contains(item.Start, leftSeparator.Length, start)) {
return true;
}
// Check that change does not affect item right separator. Note that we should not be using
// TextRange.Intersect since in case oldLength is zero (like when user is typing right before %} or }})
// TextRange.Intersect will determine that zero-length range intersects with the right separator
// which is incorrect. Typing at position 10 does not change separator at position 10. Similarly,
// deleting text right before %} or }} does not make change destructive.
var htmlToken = item as IHtmlToken;
if (htmlToken == null || htmlToken.IsWellFormed) {
int rightSeparatorStart = item.End - rightSeparator.Length;
if (start + oldLength > rightSeparatorStart) {
if (TextRange.Intersect(rightSeparatorStart, rightSeparator.Length, start, oldLength)) {
return true;
}
}
}
// Touching left separator is destructive too, like when changing {{ to {{@
// Check that change does not affect item left separator (whitespace is fine)
if (item.Start + leftSeparator.Length == start) {
if (oldLength == 0) {
string text = newText.GetText(new TextRange(start, newLength));
if (String.IsNullOrWhiteSpace(text)) {
return false;
}
}
return true;
}
int fragmentStart = item.Start + separatorInfo.LeftSeparator.Length;
fragmentStart = Math.Max(fragmentStart, start - separatorInfo.RightSeparator.Length + 1);
int changeLength = newLength - oldLength;
int fragmentEnd = item.End + changeLength;
fragmentEnd = Math.Min(fragmentEnd, start + newLength + separatorInfo.RightSeparator.Length - 1);
if (newText.IndexOf(separatorInfo.RightSeparator, TextRange.FromBounds(fragmentStart, fragmentEnd), true) >= 0) {
return true;
}
return false;
}
return true;
}
示例2: IsLineBreakInRange
private bool IsLineBreakInRange(ITextProvider textProvider, int start, int end) {
return textProvider.IndexOf('\n', TextRange.FromBounds(start, end)) >= 0;
}