本文整理汇总了C#中Span.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Span.Contains方法的具体用法?C# Span.Contains怎么用?C# Span.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Span
的用法示例。
在下文中一共展示了Span.Contains方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCaret
private bool SetCaret(Span zenSpan, bool isReverse)
{
string text = TextView.TextBuffer.CurrentSnapshot.GetText();
Span quote = FindTabSpan(zenSpan, isReverse, text, _quotes);
Span bracket = FindTabSpan(zenSpan, isReverse, text, _bracket);
if (!isReverse && bracket.Start > 0 && (bracket.Start < quote.Start || quote.Start == 0))
{
quote = bracket;
}
else if (isReverse && bracket.Start > 0 && (bracket.Start > quote.Start || quote.Start == 0))
{
quote = bracket;
}
if (zenSpan.Contains(quote.Start))
{
MoveTab(quote);
return true;
}
else if (!isReverse)
{
MoveTab(new Span(zenSpan.End, 0));
return true;
}
return false;
}
示例2: HandleTreeViewSelectedItemChangedV4
private void HandleTreeViewSelectedItemChangedV4(object sender, RoutedPropertyChangedEventArgs<object> e)
{
try
{
if (Tagger == null)
return;
if (Tokens3 != null || e.NewValue is Antlr.Runtime.Tree.ITree)
return;
using (Tagger.Update())
{
Tagger.RemoveTagSpans(tagSpan => true);
if (Snapshot == null)
return;
IParseTree selected = e.NewValue as IParseTree;
IList<IToken> tokens = Tokens4;
if (tokens != null && selected != null)
{
if (selected.SourceInterval.a >= 0 && selected.SourceInterval.b >= 0)
{
IToken startToken = tokens[selected.SourceInterval.a];
IToken stopToken = tokens[selected.SourceInterval.b];
Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
Span sourceSpan = new Span(0, Snapshot.Length);
if (sourceSpan.Contains(span))
{
ITrackingSpan trackingSpan = Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
Tagger.CreateTagSpan(trackingSpan, PredefinedTextMarkerTags.Vivid);
var activeView = ActiveViewTrackerService.ActiveView;
if (activeView != null && activeView.TextBuffer == Snapshot.TextBuffer)
activeView.ViewScroller.EnsureSpanVisible(new SnapshotSpan(Snapshot, span), EnsureSpanVisibleOptions.ShowStart);
}
}
}
else if (selected is ITerminalNode)
{
IToken token = ((ITerminalNode)selected).Symbol;
if (token.StartIndex >= 0 && token.StopIndex >= 0)
{
Span span = new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1);
Span sourceSpan = new Span(0, Snapshot.Length);
if (sourceSpan.Contains(span))
{
ITrackingSpan trackingSpan = Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
Tagger.CreateTagSpan(trackingSpan, PredefinedTextMarkerTags.Vivid);
var activeView = ActiveViewTrackerService.ActiveView;
if (activeView != null && activeView.TextBuffer == Snapshot.TextBuffer)
activeView.ViewScroller.EnsureSpanVisible(new SnapshotSpan(Snapshot, span), EnsureSpanVisibleOptions.ShowStart);
}
}
}
else if (selected is IRuleNode)
{
//if (selected.Token.StartIndex >= 0 && selected.Token.StopIndex >= 0)
//{
// IToken token = selected.Token;
// Span span = new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1);
// Span sourceSpan = new Span(0, Snapshot.Length);
// if (sourceSpan.Contains(span))
// {
// ITrackingSpan trackingSpan = Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
// Tagger.CreateTagSpan(trackingSpan, PredefinedTextMarkerTags.Vivid);
// var activeView = ActiveViewTrackerService.ActiveView;
// if (activeView != null && activeView.TextBuffer == Snapshot.TextBuffer)
// activeView.ViewScroller.EnsureSpanVisible(new SnapshotSpan(Snapshot, span), EnsureSpanVisibleOptions.ShowStart);
// }
//}
}
}
}
catch (Exception ex)
{
if (ErrorHandler.IsCriticalException(ex))
throw;
}
}
示例3: GetIntersectionSpans
public IEnumerable<ICodeClassificationSpan> GetIntersectionSpans(int lineNumebr, Span spanBoundaries)
{
if (classificationSpanToLineMap.ContainsKey(lineNumebr))
{
IList<CodeClassificationSpan> visibleSpans = classificationSpanToLineMap[lineNumebr];
foreach (CodeClassificationSpan codeToken in visibleSpans)
{
if (spanBoundaries.Contains(codeToken.Span))
{
yield return codeToken;
}
else
{
Span? intersectionSpan = codeToken.Span.Intersection(spanBoundaries);
if (intersectionSpan.HasValue)
{
yield return new CodeClassificationSpan(codeToken, intersectionSpan.Value);
}
}
}
}
}
示例4: AddClassifications
/// <summary>
/// Adds classification spans to the given collection.
/// Scans a contiguous sub-<paramref name="span"/> of a larger code span which starts at <paramref name="codeStartLine"/>.
/// </summary>
private void AddClassifications(JSScanner JSScanner, List<ClassificationSpan> classifications, SnapshotSpan span) {
Debug.Assert(span.Length > 0);
var snapshot = span.Snapshot;
int firstLine = snapshot.GetLineNumberFromPosition(span.Start);
int lastLine = snapshot.GetLineNumberFromPosition(span.End - 1);
Contract.Assert(firstLine >= 0);
_tokenCache.EnsureCapacity(snapshot.LineCount);
// find the closest line preceding firstLine for which we know categorizer state, stop at the codeStartLine:
LineTokenization lineTokenization;
int currentLine = _tokenCache.IndexOfPreviousTokenization(firstLine, 0, out lineTokenization) + 1;
object state = lineTokenization.State;
// track the previous 2 tokens to adjust our classifications of keywords
// when they shouldn't be displayed as keywords...
TokenInfoWithLine? prevToken = null, prevPrevToken = null;
// initialize the previous tokens so we can handle things like:
// foo.
// get()
// even if we're called on the line for get()
int prevLine = currentLine - 1;
while (prevLine >= 0 && prevToken == null) {
LineTokenization prevLineTokenization = GetPreviousTokenization(JSScanner, snapshot, firstLine, prevLine);
for (int i = prevLineTokenization.Tokens.Length - 1; i >= 0 && prevToken == null; i--) {
var tempToken = prevLineTokenization.Tokens[i];
if (IsValidPreviousToken(ref tempToken)) {
prevToken = prevPrevToken;
prevPrevToken = new TokenInfoWithLine() { TokenInfo = tempToken, Line = prevLine };
}
}
prevLine--;
}
while (currentLine <= lastLine) {
if (!_tokenCache.TryGetTokenization(currentLine, out lineTokenization)) {
lineTokenization = TokenizeLine(JSScanner, snapshot, state, currentLine);
_tokenCache[currentLine] = lineTokenization;
}
state = lineTokenization.State;
for (int i = 0; i < lineTokenization.Tokens.Length; i++) {
var token = lineTokenization.Tokens[i];
if (token.Category == TokenCategory.IncompleteMultiLineStringLiteral || token.Category == TokenCategory.Comment) {
IClassificationType type;
switch (token.Category) {
case TokenCategory.IncompleteMultiLineStringLiteral:
type = _provider.StringLiteral;
break;
case TokenCategory.Comment:
type = _provider.Comment;
break;
default:
type = null;
break;
}
Debug.Assert(type != null, "We should have a defined ClassificationType for every token.");
// we need to walk backwards to find the start of this multi-line string...
TokenInfo startToken = token;
int validPrevLine;
int length = startToken.SourceSpan.Length;
if (i == 0) {
length += GetLeadingMultiLineTokens(JSScanner, snapshot, token.Category, firstLine, currentLine, out validPrevLine, ref startToken);
} else {
validPrevLine = currentLine;
}
if (i == lineTokenization.Tokens.Length - 1) {
length += GetTrailingMultiLineTokens(JSScanner, snapshot, token.Category, currentLine, state);
}
var tokenSpan = new Span(SnapshotSpanToSpan(snapshot, startToken, validPrevLine).Start, length);
var intersection = span.Intersection(tokenSpan);
if ((intersection != null && intersection.Value.Length > 0) ||
(span.Length == 0 && tokenSpan.Contains(span.Start)) // handle zero-length spans
) {
classifications.Add(new ClassificationSpan(new SnapshotSpan(snapshot, tokenSpan), type));
}
} else {
ClassificationSpan classification = null;
if (token.Category == TokenCategory.Keyword) {
// check and see if we're not really a keyword...
if (IsKeywordInIdentifierContext(snapshot, prevToken, prevPrevToken, new TokenInfoWithLine() { TokenInfo = token, Line = currentLine })) {
classification = GetClassificationSpan(
span,
token,
currentLine,
CategoryMap[TokenCategory.Identifier]
//.........这里部分代码省略.........
示例5: SetCaret
private bool SetCaret(Span zenSpan, bool isReverse)
{
string text = _view.TextBuffer.CurrentSnapshot.GetText();
Span placeholders = FindTabSpan(zenSpan, isReverse, text, _placeholders);
if (zenSpan.Contains(placeholders.Start))
{
MoveTab(placeholders);
return true;
}
if (!isReverse)
{
MoveTab(new Span(zenSpan.End, 0));
return true;
}
return false;
}
示例6: testContainsInt
public void testContainsInt() {
var a = new Span(10, 300);
/* NOTE: here the span does not contain the endpoint marked as the end
* for the span. This is because the end should be placed one past the
* true end for the span. The indexes used must observe the same
* requirements for the contains function. */
Assert.False(a.Contains(9));
Assert.True(a.Contains(10));
Assert.True(a.Contains(200));
Assert.True(a.Contains(299));
Assert.False(a.Contains(300));
}
示例7: testContains
public void testContains() {
var a = new Span(500, 900);
var b = new Span(520, 600);
Assert.AreEqual(true, a.Contains(b));
}
示例8: testContainsWithLowerIntersect
public void testContainsWithLowerIntersect() {
var a = new Span(500, 900);
var b = new Span(450, 1000);
Assert.AreEqual(false, a.Contains(b));
}
示例9: testContainsWithEqual
public void testContainsWithEqual() {
var a = new Span(500, 900);
Assert.AreEqual(true, a.Contains(a));
}