public int IndexOf(string text, int start, bool ignoreCase) { return(_text.IndexOf(text, start, ignoreCase)); }
private bool IsDestructiveChangeForSeparator( ISensitiveFragmentSeparatorsInfo separatorInfo, IList <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; // If no items are affected, change is unsafe only if new region contains left side separators. if (itemsInRange.Count == 0) { // 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 (itemsInRange.Count == 1 && (itemsInRange[0].Contains(start) && itemsInRange[0].Contains(start + oldLength))) { // Check that change does not affect item left separator if (TextRange.Contains(itemsInRange[0].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 = itemsInRange[0] as IHtmlToken; if (htmlToken == null || htmlToken.IsWellFormed) { int rightSeparatorStart = itemsInRange[0].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 (itemsInRange[0].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 = itemsInRange[0].Start + separatorInfo.LeftSeparator.Length; fragmentStart = Math.Max(fragmentStart, start - separatorInfo.RightSeparator.Length + 1); int changeLength = newLength - oldLength; int fragmentEnd = itemsInRange[0].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); }
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; }
public int IndexOf(string text, int start, bool ignoreCase) => Text.IndexOf(text, start, ignoreCase);
private bool IsLineBreakInRange(ITextProvider textProvider, int start, int end) { return textProvider.IndexOf('\n', TextRange.FromBounds(start, end)) >= 0; }
private bool IsLineBreakInRange(ITextProvider textProvider, int start, int end) { return(textProvider.IndexOf('\n', TextRange.FromBounds(start, end)) >= 0); }