本文整理汇总了C#中System.Buffer.GetCharacter方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.GetCharacter方法的具体用法?C# Buffer.GetCharacter怎么用?C# Buffer.GetCharacter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Buffer
的用法示例。
在下文中一共展示了Buffer.GetCharacter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Scan
static Token Scan(Buffer b, out bool error)
{
int startPosition = b.Position;
char ch = b.GetCharacter();
error = false;
// CASE 1: Next token is a separator character
if (ch == OpenParenthesis)
return new Token(Token.Kind.Open, "(", startPosition);
else if (ch == ClosedParenthesis)
return new Token(Token.Kind.Close, ")", startPosition);
if (ch == OpenBracket)
return new Token(Token.Kind.LBracket, "(", startPosition);
else if (ch == ClosedBracket)
return new Token(Token.Kind.RBracket, ")", startPosition);
else if (ch == Comma)
return new Token(Token.Kind.Comma, ",", startPosition);
// CASE 2: Next token is a quoted string
else if (ch == QuoteChar)
{
StringBuilder stringToken = new StringBuilder();
bool sawEscape = false;
bool endOfString = false;
while (!endOfString)
{
ch = b.GetCharacter();
if (ch == EOF)
{
error = true;
return null;
}
else if (ch == Escape && !sawEscape)
{
sawEscape = true;
}
else if (sawEscape) // to do: add && IsEscapedChar(ch)
{
sawEscape = false;
stringToken.Append(ch);
}
else if (ch == QuoteChar)
{
endOfString = true;
}
else
{
stringToken.Append(ch);
}
}
return new Token(Token.Kind.String, stringToken.ToString(), startPosition);
}
// Case 3: Integer
else if (Char.IsDigit(ch) || (ch == Minus && !b.IsDelimited() && Char.IsDigit(b.Peek())))
{
StringBuilder intToken = new StringBuilder();
intToken.Append(ch);
while (!b.IsDelimited())
{
ch = b.GetCharacter();
if (Char.IsDigit(ch))
intToken.Append(ch);
else
{
error = true;
return null;
}
}
return new Token(Token.Kind.Integer, intToken.ToString(), startPosition);
}
// Case 4: Function symbol
else if (Char.IsLetterOrDigit(ch) || ch == AtSign)
{
StringBuilder symbolToken = new StringBuilder();
symbolToken.Append(ch);
while (!b.IsDelimited())
{
ch = b.GetCharacter();
if (Char.IsLetterOrDigit(ch) || ch == Underscore)
symbolToken.Append(ch);
else
{
error = true;
return null;
}
}
string str = symbolToken.ToString();
if (str == "true" || str == "false" || str == "True" || str == "False")
return new Token(Token.Kind.Boolean, str, startPosition);
else if (str == "null")
return new Token(Token.Kind.Null, str, startPosition);
else
return new Token(Token.Kind.Symbol, str, startPosition);
}
//.........这里部分代码省略.........