当前位置: 首页>>代码示例>>C#>>正文


C# TextReader.Peek方法代码示例

本文整理汇总了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;
        }
开发者ID:sibartlett,项目名称:RavenDB.Client.Spatial,代码行数:32,代码来源:WktTokenizer.cs

示例2: readEmptyCharacters

 private static void readEmptyCharacters(TextReader reader)
 {
     while (reader.Peek() >= 0 && Char.IsWhiteSpace((char)reader.Peek()))
     {
         reader.Read();
     }
 }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:7,代码来源:JsonParser.cs

示例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);
        }
开发者ID:TheModMaker,项目名称:ModMaker.Lua,代码行数:37,代码来源:NetHelpers.cs

示例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() };
        }
开发者ID:najira,项目名称:spatiallite-net,代码行数:34,代码来源:WktTokenizer.cs

示例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();
 }
开发者ID:llenroc,项目名称:HttpClient,代码行数:36,代码来源:StringEscapeUtils.cs

示例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();
 }
开发者ID:jamisliao,项目名称:Handlebars.Net,代码行数:28,代码来源:PartialParser.cs

示例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);
			}
		}
开发者ID:DinrusGroup,项目名称:D_Parser,代码行数:57,代码来源:IndentEngineWrapper.cs

示例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);
            }
        }
开发者ID:zibler,项目名称:zibler,代码行数:56,代码来源:TypeNameParser.cs

示例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;
 }
开发者ID:BclEx,项目名称:BclEx-Abstract,代码行数:10,代码来源:JsonParserUtil.cs

示例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());
        }
开发者ID:SimpleGitVersion,项目名称:CodeCake,代码行数:55,代码来源:FormatParser.cs

示例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() );
     }
 }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:11,代码来源:CsvLineParser.cs

示例13: GetNextWord

 public static void GetNextWord(TextReader reader)
 {
     while (!IsEndOfBuffer(reader))
     {
         if (!IsSeparator((char)reader.Peek()) || IsNewLine((char)reader.Peek()))
         {
             break;
         }
         reader.Read();
     }
 }
开发者ID:oguna,项目名称:AssimpSharp,代码行数:11,代码来源:ObjTools.cs

示例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();
        }
开发者ID:derrills1,项目名称:ccnet_gitmode,代码行数:57,代码来源:VstsHistoryParser.cs

示例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();
 }
开发者ID:oguna,项目名称:AssimpSharp,代码行数:14,代码来源:ObjTools.cs


注:本文中的System.IO.TextReader.Peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。