本文整理汇总了C#中System.IO.TextReader.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.Peek方法的具体用法?C# TextReader.Peek怎么用?C# TextReader.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tokenize
public WktTokenQueue Tokenize(TextReader reader)
{
var queue = new WktTokenQueue();
var builder = new StringBuilder();
var nextCh = reader.Peek();
while (nextCh != -1)
{
var ch = (char)reader.Read();
var type = GetTokenType(ch);
nextCh = reader.Peek();
var nextType = WktTokenType.None;
if (nextCh != -1)
nextType = GetTokenType((char)nextCh);
if (type != WktTokenType.Whitespace)
{
builder.Append(ch);
if (type != nextType ||
type == WktTokenType.Comma ||
type == WktTokenType.LeftParenthesis ||
type == WktTokenType.RightParenthesis)
{
if (type != WktTokenType.Whitespace)
queue.Enqueue(new WktToken(type, builder.ToString()));
builder.Remove(0, builder.Length);
}
}
}
return queue;
}
示例2: readEmptyCharacters
private static void readEmptyCharacters(TextReader reader)
{
while (reader.Peek() >= 0 && Char.IsWhiteSpace((char)reader.Peek()))
{
reader.Read();
}
}
示例3: ReadNumber
/// <summary>
/// Reads a number from a text reader.
/// </summary>
/// <param name="input">The input to read from.</param>
/// <returns>The number read.</returns>
public static double ReadNumber(TextReader input)
{
// TODO: Check whether this is used in the parser (move to ModMaker.Lua) and make this
// consitent with the spec.
StringBuilder build = new StringBuilder();
int c = input.Peek();
int l = c;
bool hex = false;
CultureInfo ci = CultureInfo.CurrentCulture;
if (c == '0')
{
input.Read();
c = input.Peek();
if (c == 'x' || c == 'X')
{
input.Read();
hex = true;
}
}
while (c != -1 && (char.IsNumber((char)c) || (hex && ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) ||
(!hex && (c == ci.NumberFormat.NumberDecimalSeparator[0] || c == '-' || (l != '.' && c == 'e')))))
{
input.Read();
build.Append((char)c);
l = c;
c = input.Peek();
}
return double.Parse(build.ToString(), ci);
}
示例4: Tokenize
/// <summary>
/// Processes text from TextReader and splits it into tokens.
/// </summary>
/// <param name="reader">The TextReader to read string from</param>
/// <returns>The collection parsed tokens of the input string</returns>
public static IEnumerable<WktToken> Tokenize(TextReader reader)
{
StringBuilder stringBuffer = new StringBuilder();
if (reader.Peek() == -1) {
yield break;
}
char ch = (char)reader.Read();
stringBuffer.Append(ch);
TokenType lastToken = WktTokenizer.GetTokenType(ch);
while (reader.Peek() != -1) {
ch = (char)reader.Read();
TokenType token = WktTokenizer.GetTokenType(ch);
// tokens COMMA, LEFT_PARENTHESIS and RIGHT_PARENTHESIS can not be grupped together
if ((token != lastToken) || token == TokenType.COMMA || token == TokenType.LEFT_PARENTHESIS || token == TokenType.RIGHT_PARENTHESIS) {
yield return new WktToken() { Type = lastToken, Value = stringBuffer.ToString() };
stringBuffer.Clear();
lastToken = token;
}
stringBuffer.Append(ch);
}
yield return new WktToken() { Type = lastToken, Value = stringBuffer.ToString() };
}
示例5: Escape
/// <summary>
/// Escapes the characters in a String
/// </summary>
/// <param name="reader">the input string reader to escaping.</param>
/// <returns>a string that has been escaped.</returns>
public static string Escape(TextReader reader)
{
var sb = new StringBuilder();
var code = -1;
while ((code = reader.Read()) >= 0)
{
var ch = (char)code;
if (ch == '<')
{
sb.Append(ch);
if (reader.Peek() != -1 && ((char)reader.Peek()) == '/')
{
sb.Append(@"\/");
reader.Read();
}
}
else
{
string escapeChar = null;
if (_escapeSequences.TryGetValue(ch, out escapeChar))
{
sb.Append(escapeChar);
}
else
{
sb.Append(ch);
}
}
}
return sb.ToString();
}
示例6: AccumulatePartial
private string AccumulatePartial(TextReader reader)
{
StringBuilder buffer = new StringBuilder();
buffer.Append(">");
do
{
reader.Read();
}
while(char.IsWhiteSpace((char)reader.Peek()));
while(true)
{
var peek = (char)reader.Peek();
if (peek == '}' || peek == '~' || char.IsWhiteSpace(peek))
{
break;
}
var node = reader.Read();
if (node == -1)
{
throw new InvalidOperationException("Reached end of template before the expression was closed.");
}
else
{
buffer.Append((char)node);
}
}
return buffer.ToString();
}
示例7: CorrectIndent
public static void CorrectIndent(TextReader code, int startOffset, int endOffset, Action<int, int, string> documentReplace, DFormattingOptions options = null, ITextEditorOptions textStyle = null, bool formatLastLine = true)
{
textStyle = textStyle ?? TextEditorOptions.Default;
var eng = new IndentEngine(options ?? DFormattingOptions.CreateDStandard(), textStyle.TabsToSpaces, textStyle.IndentSize, textStyle.KeepAlignmentSpaces);
var replaceActions = new List<DFormattingVisitor.TextReplaceAction>();
int originalIndent = 0;
bool hadLineBreak = true;
int n = 0;
for (int i = 0; i <= endOffset && (n = code.Read()) != -1; i++)
{
if(n == '\r' || n == '\n')
{
if (i >= startOffset && !eng.LineBeganInsideString)
replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent));
hadLineBreak = true;
originalIndent = 0;
if (code.Peek() == '\n')
{
eng.Push((char)code.Read());
i++;
}
}
else if(hadLineBreak)
{
if(n == ' ' || n== '\t')
originalIndent++;
else
hadLineBreak = false;
// If there's code left, format the last line of the selection either
if (i == endOffset && formatLastLine)
endOffset++;
}
eng.Push((char)n);
}
// Also indent the last line if we're at the EOF.
if (code.Peek() == -1 || (formatLastLine && n != '\r' && n != '\n'))
{
if(!eng.LineBeganInsideString)
replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent));
}
// Perform replacements from the back of the document to the front - to ensure offset consistency
for(int k = replaceActions.Count - 1; k>=0; k--)
{
var rep = replaceActions[k];
if(rep.RemovalLength > 0 || rep.NewText.Length != 0)
documentReplace(rep.Offset, rep.RemovalLength, rep.NewText);
}
}
示例8: ParseTypeName
public AssemblyQualifiedTypeName ParseTypeName(string text, string defaultNamespace, string defaultAssembly)
{
text = text.Trim();
StringBuilder type = new StringBuilder(text.Length);
string assembly = StringHelper.IsEmpty(defaultAssembly) ? null : defaultAssembly;
try
{
bool seenNamespace = false;
input = new StringReader(text);
int code;
while ((code = input.Peek()) != -1)
{
char ch = (char) code;
if (ch == '.')
{
seenNamespace = true;
}
if (ch == ',')
{
input.Read();
assembly = AssemblyName();
if (input.Peek() != -1)
{
throw new ParserException("Extra characters found at the end of the type name");
}
}
else if (ch == '[')
{
type.Append(BracketedPart());
}
else
{
type.Append(PossiblyEscapedCharacter());
}
}
input.Close();
if (!seenNamespace && StringHelper.IsNotEmpty(defaultNamespace))
{
type.Insert(0, '.')
.Insert(0, defaultNamespace);
}
return new AssemblyQualifiedTypeName(type.ToString(), assembly);
}
catch (Exception e)
{
throw new ArgumentException("Invalid fully-qualified type name: " + text, "text", e);
}
}
示例9: ParseImpl
public static object ParseImpl(TextReader reader, GRGEN_LIBGR.AttributeType attrType, GRGEN_LIBGR.IGraph graph)
{
char lookahead = (char)reader.Peek();
if(lookahead == 'o')
{
reader.Read(); // eat 'o'
return new Own();
}
else if(lookahead == 'p')
{
reader.Read(); // eat 'p'
StringBuilder sb = new StringBuilder();
while(reader.Peek() != ',' && reader.Peek() != ')') // attributes are separated by , a node/edge terminated by ) in .grs
sb.Append((char)reader.Read()); // eat non ',', ')'
OwnPown op = new OwnPown();
op.ehe = sb.ToString();
return op;
}
else if(lookahead == 'h')
{
reader.Read(); // eat 'h'
StringBuilder sb = new StringBuilder();
while(reader.Peek() != ';')
sb.Append((char)reader.Read()); // eat non ';'
string ehe = sb.ToString();
sb.Length = 0;
reader.Read(); // eat ';'
while(reader.Peek() != ',' && reader.Peek() != ')') // attributes are separated by , a node/edge terminated by ) in .grs
sb.Append((char)reader.Read()); // eat non ',',')'
OwnPownHome oph = new OwnPownHome();
oph.ehe = ehe;
oph.aha = sb.ToString();
return oph;
}
else
{
if(reader.Peek() == 'n')
{
reader.Read();
if(reader.Peek() == 'u')
{
reader.Read();
if(reader.Peek() == 'l')
{
reader.Read();
if(reader.Peek() == 'l')
{
reader.Read();
return null;
}
}
}
}
throw new Exception("parsing failure");
}
}
开发者ID:ArsenShnurkov,项目名称:GrGen,代码行数:56,代码来源:ExternalAttributeEvaluationModelExternalFunctionsImpl.cs
示例10: PeekNextChar
public static char PeekNextChar(TextReader r, bool ignoreWhitespace)
{
var c = (char)r.Peek();
while (ignoreWhitespace && char.IsWhiteSpace(c))
{
r.Read();
c = (char)r.Peek();
}
return c;
}
示例11: ParseProperty
private static FormatToken ParseProperty(TextReader reader)
{
reader.Read(); // Consume
if (reader.Peek() == -1)
{
return new LiteralToken("{");
}
if ((char)reader.Peek() == '{')
{
reader.Read();
return new LiteralToken("{{");
}
var builder = new StringBuilder();
while (true)
{
var current = reader.Peek();
if (current == -1)
{
break;
}
var character = (char)current;
if (character == '}')
{
reader.Read();
var accumulated = builder.ToString();
var parts = accumulated.Split(new[] { ':' }, StringSplitOptions.None);
if (parts.Length > 1)
{
var name = parts[0];
var format = string.Join(string.Empty, parts.Skip(1));
var positional = IsNumeric(name);
if (!positional)
{
throw new FormatException("Input string was not in a correct format.");
}
var position = int.Parse(name, CultureInfo.InvariantCulture);
return new PropertyToken(position, format);
}
else
{
var positional = IsNumeric(accumulated);
if (!positional)
{
throw new FormatException("Input string was not in a correct format.");
}
var position = int.Parse(accumulated, CultureInfo.InvariantCulture);
return new PropertyToken(position, null);
}
}
builder.Append((char)reader.Read());
}
return new LiteralToken(builder.ToString());
}
示例12: parseCommaSeparatedField
private static void parseCommaSeparatedField( TextReader tr, List<string> fields )
{
if( tr.Peek() != -1 ) {
string field;
if( tr.Peek() != '"' )
field = parseSimpleField( tr );
else
field = parseQuotedField( tr );
fields.Add( field.Trim() );
}
}
示例13: GetNextWord
public static void GetNextWord(TextReader reader)
{
while (!IsEndOfBuffer(reader))
{
if (!IsSeparator((char)reader.Peek()) || IsNewLine((char)reader.Peek()))
{
break;
}
reader.Read();
}
}
示例14: Parse
/// <summary>
/// Parse the output from a TFS History check <see cref="Modification"/>s.
/// </summary>
/// <param name="vstsLog">The output of the "TF History command.</param>
/// <param name="from">The starting timestamp.</param>
/// <param name="to">The ending timestamp.</param>
/// <returns>A list of modifications between the two timestamps, possibly empty.</returns>
public Modification[] Parse(TextReader vstsLog, DateTime from, DateTime to)
{
startTime = from;
endTime = to;
string logFileLine;
StringBuilder changeSet = new StringBuilder(null);
var mods = new List<Modification>();
if (vstsLog.Peek() != -1 && Convert.ToChar(vstsLog.Peek()) == Convert.ToChar("-"))
{
while ((logFileLine = vstsLog.ReadLine()) != null)
{
if (logFileLine == "-------------------------------------------------------------------------------")
{
if (changeSet.Length != 0)
{
Modification[] tempMods = ParseChangeSet(changeSet);
foreach (Modification change in tempMods)
{
mods.Add(change);
}
changeSet = new StringBuilder(null);
}
}
else if (logFileLine == "No history entries were found for the item and version combination specified")
{
return new Modification[0];
}
else
{
changeSet.AppendLine(logFileLine);
}
}
if (!string.IsNullOrEmpty(changeSet.ToString()))
{
Modification[] tempMods = ParseChangeSet(changeSet);
foreach (Modification change in tempMods)
{
mods.Add(change);
}
}
}
return mods.ToArray();
}
示例15: CopyNextWord
public static string CopyNextWord(TextReader sr)
{
StringBuilder sb = new StringBuilder();
GetNextWord(sr);
while (!IsSeparator((char)sr.Peek()) && !IsEndOfBuffer(sr))
{
sb.Append((char)sr.Read());
if (sr.Peek() == -1)
{
break;
}
}
return sb.ToString();
}