本文整理汇总了C#中SnapshotPoint.GetChar方法的典型用法代码示例。如果您正苦于以下问题:C# SnapshotPoint.GetChar方法的具体用法?C# SnapshotPoint.GetChar怎么用?C# SnapshotPoint.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SnapshotPoint
的用法示例。
在下文中一共展示了SnapshotPoint.GetChar方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveToken
/// <summary>
/// Removes a token using the enhanced token stream class.
/// </summary>
/// <param name="sql"></param>
/// <param name="position"></param>
/// <returns></returns>
private CommonTokenStream RemoveToken(string sql, SnapshotPoint snapPos)
{
MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
//ANTLRInputStream input = new ANTLRInputStream(ms);
Version ver = LanguageServiceUtil.GetVersion(LanguageServiceUtil.GetConnection().ServerVersion);
MySQLLexer lexer = new MySQLLexer(input);
lexer.MySqlVersion = ver;
TokenStreamRemovable tokens = new TokenStreamRemovable(lexer);
IToken tr = null;
int position = snapPos.Position;
tokens.Fill();
if (!char.IsWhiteSpace(snapPos.GetChar()))
{
foreach (IToken t in tokens.GetTokens())
{
if ((t.StartIndex <= position) && (t.StopIndex >= position))
{
tr = t;
break;
}
}
tokens.Remove(tr);
}
return tokens;
}
示例2: ReadComment
public static SnapshotSpan ReadComment(this ITextSnapshot snapshot, ref SnapshotPoint point)
{
if (point.Position == snapshot.Length || point.GetChar() != RobotsTxtSyntaxFacts.Comment)
return new SnapshotSpan(point, 0);
return snapshot.ReadToLineEndWhile(ref point, _ => true);
}
示例3: IsPreceededByEventAddSyntax
/// <summary>
/// Is the provided SnapshotPoint preceded by the '+= SomeEventType(Some_HandlerName' line
/// </summary>
private bool IsPreceededByEventAddSyntax(SnapshotSpan span)
{
// First find the last + character
var snapshot = span.Snapshot;
SnapshotPoint? plusPoint = null;
for (int i = span.Length - 1; i >= 0; i--)
{
var position = span.Start.Position + i;
var point = new SnapshotPoint(snapshot, position);
if (point.GetChar() == '+')
{
plusPoint = point;
break;
}
}
if (plusPoint == null)
{
return false;
}
var eventSpan = new SnapshotSpan(plusPoint.Value, span.End);
var eventText = eventSpan.GetText();
return
s_fullEventSyntaxRegex.IsMatch(eventText) ||
s_shortEventSyntaxRegex.IsMatch(eventText);
}
示例4: ReadExact
public static SnapshotSpan ReadExact(this ITextSnapshot snapshot, ref SnapshotPoint point, char @char)
{
SnapshotPoint start = point;
if (point < snapshot.Length && point.GetChar() == @char)
{
point = point + 1;
return new SnapshotSpan(start, point);
}
return new SnapshotSpan(point, 0);
}
示例5: ReadToLineEndWhile
public static SnapshotSpan ReadToLineEndWhile(this ITextSnapshot snapshot, ref SnapshotPoint point, Predicate<char> predicate, bool rewindWhiteSpace = true)
{
SnapshotPoint start = point;
while (
point.Position < snapshot.Length &&
point.GetChar() != '\n' && point.GetChar() != '\r' &&
predicate(point.GetChar())
)
point = point + 1;
if (rewindWhiteSpace)
{
while (
point - 1 >= start &&
Char.IsWhiteSpace((point - 1).GetChar())
)
point = point - 1;
}
return new SnapshotSpan(start, point);
}
示例6: ReadDelimiter
public static SnapshotSpan ReadDelimiter(this ITextSnapshot snapshot, ref SnapshotPoint point)
{
if (point.Position == snapshot.Length)
return new SnapshotSpan(point, 0);
var @char = point.GetChar();
if (@char != RobotsTxtSyntaxFacts.NameValueDelimiter)
return new SnapshotSpan(point, 0);
point = point + 1;
return new SnapshotSpan(point - 1, 1);
}
示例7: GetCharOrDefault2
public void GetCharOrDefault2()
{
Create("foo", "bar");
var endPoint = new SnapshotPoint(_buffer.CurrentSnapshot, _buffer.CurrentSnapshot.Length);
var didSee = false;
try
{
var notUsed = endPoint.GetChar();
}
catch (ArgumentException)
{
didSee = true;
}
Assert.IsTrue(didSee);
Assert.AreEqual('f', SnapshotPointUtil.GetCharOrDefault(endPoint, 'f'));
}
示例8: GetVariableNameAndSpan
private static string GetVariableNameAndSpan(SnapshotPoint point, out SnapshotSpan span)
{
var line = point.GetContainingLine();
var hoveredIndex = point.Position - line.Start.Position;
var c = point.GetChar();
if (!Char.IsDigit(c) && !Char.IsLetter(c) && (c != '_'))
{
span = new SnapshotSpan();
return null;
}
// Find the name of the variable under the mouse pointer (ex: 'gesture.Pose.Name' when the mouse is hovering over the 'o' of pose)
var match = m_variableExtractor.Matches(line.GetText()).OfType<Match>().SingleOrDefault(x => x.Index <= hoveredIndex && (x.Index + x.Length) >= hoveredIndex);
if ((match == null) || (match.Value.Length == 0))
{
span = new SnapshotSpan();
return null;
}
var name = match.Value;
// Find the first '.' after the hoveredIndex and cut it off
int relativeIndex = hoveredIndex - match.Index;
var lastIndex = name.IndexOf('.', relativeIndex);
if (lastIndex >= 0)
{
name = name.Substring(0, lastIndex);
}
else
{
lastIndex = name.Length;
}
var matchStartIndex = name.LastIndexOf('.', relativeIndex) + 1;
span = new SnapshotSpan(line.Start.Add(match.Index + matchStartIndex), lastIndex - matchStartIndex);
return name;
}
示例9: AddAdornments
private void AddAdornments()
{
Debug.Assert(_easyMotionUtil.State == EasyMotionState.LookingForDecision);
if (_wpfTextView.InLayout)
{
return;
}
_navigateMap.Clear();
var textViewLines = _wpfTextView.TextViewLines;
var startPoint = textViewLines.FirstVisibleLine.Start;
var endPoint = textViewLines.LastVisibleLine.End;
var snapshot = startPoint.Snapshot;
var count = 0;
for (int i = startPoint.Position; i < endPoint.Position; i++)
{
var point = new SnapshotPoint(snapshot, i);
if (char.ToLower(point.GetChar()) == char.ToLower(_easyMotionUtil.TargetChar))
{
count++;
}
}
var navigationKeys = _navigationKeysShort;
if (count > _navigationKeysShort.Length)
{
navigationKeys = _navigationKeysLong;
}
int navigateIndex = 0;
for (int i = startPoint.Position; i < endPoint.Position; i++)
{
var point = new SnapshotPoint(snapshot, i);
if (char.ToLower(point.GetChar()) == char.ToLower(_easyMotionUtil.TargetChar) && navigateIndex < navigationKeys.Length)
{
var key = navigationKeys[navigateIndex];
navigateIndex++;
AddNavigateToPoint(textViewLines, point, key);
}
}
if (navigateIndex == 0)
{
_easyMotionUtil.ChangeToLookingCharNotFound();
}
}
示例10: GetWordKind
static WordKind GetWordKind(SnapshotPoint currentPosition) {
if (currentPosition.Position >= currentPosition.Snapshot.Length)
return WordKind.Whitespace;
return GetWordKind(currentPosition.GetChar());
}
示例11: GetWordSpanFromPosition
private static SnapshotSpan GetWordSpanFromPosition(SnapshotPoint positon)
{
if (positon.Position >= positon.Snapshot.Length)
return new SnapshotSpan(positon, 0);
char charAtPos = positon.GetChar();
string text = positon.Snapshot.GetText();
ITextSnapshotLine lineSnapshot = positon.Snapshot.GetLineFromPosition(positon);
int left, right;
left = right = positon.Position;
if (IsWordChar(charAtPos))
{
while (left - 1 >= lineSnapshot.Start.Position && IsWordChar(text[left - 1]))
{
left--;
}
while (right + 1 < lineSnapshot.End.Position && IsWordChar(text[right + 1]))
{
right++;
}
return new SnapshotSpan(positon.Snapshot, left, right + 1 - left);
}
else
{
return new SnapshotSpan(positon, 1);
}
}
示例12: FindOtherBrace
// returns true if brace is actually a brace.
private bool FindOtherBrace(SnapshotPoint possibleBrace, out SnapshotPoint? otherBrace)
{
otherBrace = null;
var rainbow = this.textBuffer.Get<RainbowProvider>();
if ( rainbow == null ) {
return false;
}
if ( !possibleBrace.IsValid() ) {
return false;
}
if ( !rainbow.BraceCache.Language.BraceList.Contains(possibleBrace.GetChar()) ) {
return false;
}
var bracePair = rainbow.BraceCache.GetBracePair(possibleBrace);
if ( bracePair == null ) {
return true;
}
if ( possibleBrace.Position == bracePair.Item1.Position ) {
otherBrace = bracePair.Item2.ToPoint(possibleBrace.Snapshot);
} else {
otherBrace = bracePair.Item1.ToPoint(possibleBrace.Snapshot);
}
return true;
}
示例13: GetCompleteStatement
private string GetCompleteStatement(
ITextSnapshot snapshot, SnapshotPoint snapPos, out StringBuilder sbErrors, out ITree treeStmt)
{
int position = snapPos.Position;
StringBuilder sb = new StringBuilder();
CommonTokenStream tokens;
string sql = snapshot.GetText();
MySQL51Parser.statement_list_return r =
LanguageServiceUtil.ParseSql( sql, false, out sb, out tokens);
sbErrors = sb;
if (sbErrors.Length != 0)
position--;
StringBuilder sbTokens = new StringBuilder();
ITree t = r.Tree as ITree;
treeStmt = t;
if (t.IsNil)
{
ITree child = null;
for (int idx = 0; idx < t.ChildCount; idx++)
{
child = t.GetChild(idx);
if (child.TokenStartIndex == -1 || child.TokenStopIndex == -1) return null;
if ((position >= tokens.Get(child.TokenStartIndex).StartIndex) &&
(position <= tokens.Get(child.TokenStopIndex).StopIndex))
{
break;
}
}
treeStmt = child;
}
else
{
treeStmt = t;
}
//int upperToken = (sb.Length == 0) ? treeStmt.TokenStopIndex - 1 : treeStmt.TokenStopIndex;
string sqlOutput;
int lastToken = treeStmt.TokenStopIndex;
// Get last not EOF token
while (tokens.Get(lastToken).Text == "<EOF>" && lastToken > 0)
lastToken--;
int len =
tokens.Get( treeStmt.TokenStopIndex ).StopIndex -
tokens.Get( treeStmt.TokenStartIndex ).StartIndex + 1;
if (char.IsWhiteSpace(snapPos.GetChar()))
{
sqlOutput = sql.Substring(tokens.Get(treeStmt.TokenStartIndex).StartIndex,
Math.Min(len, sql.Length - tokens.Get(treeStmt.TokenStartIndex).StartIndex));
}
else
{
// remove last token
// sometimes the parser itself removes the last token.
if ((sbErrors.Length == 0) || (tokens.Get(lastToken).StopIndex - 1 == position))
{
if (tokens.Get(lastToken).StopIndex - 1 == position &&
lastToken != treeStmt.TokenStartIndex && lastToken > 0 ) lastToken--;
int start = tokens.Get(treeStmt.TokenStartIndex).StartIndex,
stop = tokens.Get( lastToken ).StartIndex;
sqlOutput = sql.Substring(start, Math.Min(stop - start, sql.Length - start));
}
else
{
sqlOutput = sql.Substring(tokens.Get(treeStmt.TokenStartIndex).StartIndex,
Math.Min(len, sql.Length - tokens.Get(treeStmt.TokenStartIndex).StartIndex));
}
}
//if ( /*treeStmt.TokenStartIndex < treeStmt.TokenStopIndex && */
// char.IsWhiteSpace(snapPos.GetChar()))
//{
// stop = tokens.Get(treeStmt.TokenStopIndex - 1).StopIndex;
//}
//else
//{
// stop = tokens.Get(treeStmt.TokenStopIndex).StartIndex;
//}
//int start = tokens.Get(treeStmt.TokenStartIndex).StartIndex;
// //stop = tokens.Get(upperToken).StopIndex;
////string sqlOutput = sql.Substring(start, Math.Min(stop - start + 1, sql.Length - start));
//if (treeStmt is CommonErrorNode || sbErrors.Length != 0)
//{
// sqlOutput = sql.Substring(start, sql.Length - start);
//}
//else
//{
// sqlOutput = sql.Substring(start, Math.Min(stop - start + 1, sql.Length - start));
//}
treeStmt = LanguageServiceUtil.ParseSql(sqlOutput, false, out sbErrors).Tree as ITree;
return sqlOutput;
}