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


C# StringReader.Peek方法代码示例

本文整理汇总了C#中System.IO.StringReader.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.Peek方法的具体用法?C# StringReader.Peek怎么用?C# StringReader.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringReader的用法示例。


在下文中一共展示了StringReader.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadADateTime

 public static bool ReadADateTime(StringReader i_sr, out DateTime DateTime)
 {
     DateTime = new DateTime();
     string key = "";
     char ch = (char)i_sr.Peek();
     while (!IsEmptySpace(ch) && !IsToken(ch))
     {
         key += (char)i_sr.Read();
         ch = (char)i_sr.Peek();
     }
     string[] nums = key.Split('.');
     if (nums.Length != 3)
     {
         return false;
     }
     try
     {
         DateTime = new DateTime(Int32.Parse(nums[0]), Int32.Parse(nums[1]), Int32.Parse(nums[2]));
     }
     catch (FormatException)
     {
         Debug.Assert(false, "Bad DateTime Format");
     }
     catch (OverflowException)
     {
         Debug.Assert(false, "Bad DateTime Format");
     }
     return true;
 }
开发者ID:OnionMoeCat,项目名称:UmbraChinaCK2,代码行数:29,代码来源:Reader.cs

示例2: Factor

 /* The Method Factor checks if the next Element in the String is an Element of the Lists
 * varibles or digit or read.peek() is -1 (then theres no next element in the string) if not it has to be a "(" otherwise the expression is false
 */
 private void Factor(StringReader reader)
 {
     if (variables.Contains((char)reader.Peek()))
     {
         reader.Read();
         return;
     }
     else if (digit.Contains((char)reader.Peek()))
     {
         reader.Read();
         Constant(reader);
         return;
     }
     else if ((char)reader.Peek() == '(')
     {
         reader.Read();
         Expression(reader);
         if ((char)reader.Peek() == ')')
         {
             reader.Read();
             return;
         }
         else
         {
             throw new ParseError("\")\" expected");
         }
     }
     else if (reader.Peek() == -1) // wenn der reader -1 als nächstes zeichen sieht dann ist string zu ende gelesen
     {
         return;
     }
     else throw new ParseError("invalid factor in "+ expressionString);
 }
开发者ID:MarvinWeiss,项目名称:Inf3_Gruppe4_WS15,代码行数:36,代码来源:Parser.cs

示例3: RemoveSpaces2

        public static string RemoveSpaces2(string value, int length)
        {
            var stringBuilder = new StringBuilder();
            using (var stringReader = new StringReader(value))
            {
                while (stringReader.Peek() != -1)
                {
                    var ch = (char)stringReader.Peek();
                    if (char.IsWhiteSpace(ch))
                    {
                        while (char.IsWhiteSpace(ch))
                        {
                            stringReader.Read();
                            ch = (char)stringReader.Peek();
                        }

                        if (stringBuilder.Length != 0 && stringBuilder.Length < length)
                        {
                            stringBuilder.Append("%20");
                        }
                    }
                    else
                    {
                        stringBuilder.Append((char)stringReader.Read());
                    }
                }
            }

            return stringBuilder.ToString();
        }
开发者ID:TerraVenil,项目名称:Algorithms,代码行数:30,代码来源:StringRemoveSpaces.cs

示例4: preProcess

 private bool preProcess(int type = 1)
 {
     String input = txtInput.Text;
     StringReader sReader = new StringReader(input);
     String tmp;
     switch(type) {
         case 1:
             // postfix
             while (sReader.Peek() != -1)
             {
                 tmp = sReader.ReadLine();
                 tmp = tmp.Trim();
                 if (tmp.IndexOf(" ") > 0)
                 {
                     postfix.Clear();
                     MessageBox.Show("Please input the valid string format (separate each \"node\" with <enter> and no space is allowed in a line)", "Invalid Input!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return false;
                 }
                 postfix.Add(new Postfix(tmp));
             }
             break;
         case 2:
             // pseudocode
             while (sReader.Peek() != -1)
             {
                 tmp = sReader.ReadLine();
             }
             break;
     }
     return true;
 }
开发者ID:Rudy9317,项目名称:Tekkom,代码行数:31,代码来源:FormPseudoCode.cs

示例5: Scan

        public IEnumerable<Token> Scan(string code)
        {
            using (TextReader textReader = new StringReader(code))
            {
                char chr;
                string name;
                Kind keyword;
                while (textReader.Peek() != -1)
                {
                    chr = (char)textReader.Peek();

                    if (chr == '[')
                    {
                        name = ScannAttribute(textReader);
                        yield return Token.Attribute(name);
                    }
                    else if (char.IsLetter(chr))
                    {
                        name = ScanName(textReader);
                        keyword = ConvertToKeyword(name);
                        if (keyword == Kind.Name)
                            yield return Token.Name(name);
                        else
                            yield return Token.Keyword(keyword);
                    }
                    else
                        textReader.Read();
                }

                yield return Token.EOF;
            }
        }
开发者ID:aklefdal,项目名称:TinyMVVM,代码行数:32,代码来源:Scanner.cs

示例6: Scan

        public IEnumerable<Token> Scan(string expression)
        {
            _reader = new StringReader(expression);

            var tokens = new List<Token>();
            while (_reader.Peek() != -1)
            {
                var c = (char)_reader.Peek();
                if (Char.IsWhiteSpace(c))
                {
                    _reader.Read();
                    continue;
                }

                if (Char.IsDigit(c))
                {
                    var nr = ParseNumber();
                    tokens.Add(new NumberConstantToken(nr));
                }
                else if (c == '-')
                {
                    tokens.Add(new MinusToken());
                    _reader.Read();
                }
                else if (c == '+')
                {
                    tokens.Add(new PlusToken());
                    _reader.Read();
                }
                else
                    throw new Exception("Unknown character in expression: " + c);
            }

            return tokens;
        }
开发者ID:santosh-mnrec,项目名称:Compiler,代码行数:35,代码来源:PlusMinusTokenizer.cs

示例7: TransformCssFile

        // The parsing logic is based on http://www.w3.org/TR/CSS2/syndata.html.
        internal static string TransformCssFile( string sourceCssText )
        {
            sourceCssText = RegularExpressions.RemoveMultiLineCStyleComments( sourceCssText );

            var customElementsDetected = from Match match in Regex.Matches( sourceCssText, customElementPattern ) select match.Value;
            customElementsDetected = customElementsDetected.Distinct();
            var knownCustomElements = CssPreprocessingStatics.Elements.Select( ce => reservedCustomElementPrefix + ce.Name );
            var unknownCustomElements = customElementsDetected.Except( knownCustomElements ).ToList();
            if( unknownCustomElements.Any() ) {
                throw new MultiMessageApplicationException(
                    unknownCustomElements.Select( e => "\"" + e + "\" begins with the reserved custom element prefix but is not a known custom element." ).ToArray() );
            }

            using( var writer = new StringWriter() ) {
                var buffer = new StringBuilder();
                using( var reader = new StringReader( sourceCssText ) ) {
                    char? stringDelimiter = null;
                    while( reader.Peek() != -1 ) {
                        var c = (char)reader.Read();

                        // escaped quote, brace, or other character
                        if( c == '\\' ) {
                            buffer.Append( c );
                            if( reader.Peek() != -1 )
                                buffer.Append( (char)reader.Read() );
                        }

                        // string delimiter
                        else if( !stringDelimiter.HasValue && ( c == '\'' || c == '"' ) ) {
                            buffer.Append( c );
                            stringDelimiter = c;
                        }
                        else if( stringDelimiter.HasValue && c == stringDelimiter ) {
                            buffer.Append( c );
                            stringDelimiter = null;
                        }

                        // selector delimiter
                        else if( !stringDelimiter.HasValue && ( c == ',' || c == '{' ) ) {
                            writer.Write( getTransformedSelector( buffer.ToString() ) );
                            writer.Write( c );
                            buffer = new StringBuilder();
                        }
                        else if( !stringDelimiter.HasValue && c == '}' ) {
                            writer.Write( buffer.ToString() );
                            writer.Write( c );
                            buffer = new StringBuilder();
                        }

                        // other character
                        else
                            buffer.Append( c );
                    }
                }
                writer.Write( buffer.ToString() );
                return writer.ToString();
            }
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:59,代码来源:CssPreprocessor.cs

示例8: Expression

 /* The Method Expression calls the Method Term because the first Element of
 * a valid expression has to be a term and checks if the specification: term {(+|-) term} is fulfilled
 */
 private void Expression(StringReader reader)
 {
     Term(reader);
     while ((char)reader.Peek() == '+' || (char)reader.Peek() == '-')
     {
         reader.Read();
         Term(reader);
     }
 }
开发者ID:MarvinWeiss,项目名称:Inf3_Gruppe4_WS15,代码行数:12,代码来源:Parser.cs

示例9: ConsumeIdentifier

        /// <summary>
        /// Consume a string of lower case characters
        /// </summary>
        /// <param name="stream">Stream to read from</param>
        /// <param name="target">Target to read to</param>
        /// <returns>True when succesful (target contains something)
        /// </returns>
        public static bool ConsumeIdentifier(StringReader stream, out string target)
        {
            StringBuilder sbl = new StringBuilder ();

            while ((stream.Peek() >= (int)'a') && (stream.Peek() <= (int)'z'))
                sbl.Append ((char)stream.Read ());

            target = sbl.ToString();
            return target.Length > 0;
        }
开发者ID:strandtentje,项目名称:nachomark,代码行数:17,代码来源:Parsing.cs

示例10: Load

        public void Load()
        {
            // Clear existing data
            lstSettings.Clear();
            lstCats.Clear();

            // Check it exists
            if (!File.Exists(strFilename)) return;

            // Read the file
            byte[] data = File.ReadAllBytes(strFilename);
            string content = ASCIIEncoding.ASCII.GetString(data);
            content = content.Replace(Environment.NewLine, "\n");

            // Set the current category
            string curCat = "Default";

            // Create a reader
            StringReader rdr = new StringReader(content);
            string parsed = "";

            // Loop
            for (char c = rdr.Peek(); c != '\0'; c = rdr.Peek())
            {
                parsed += c;

                // See what the character represents
                if (Regex.IsMatch(c.ToString(), ptnCategoryStart))
                {
                    rdr.Read();
                    curCat = rdrReadCategory(rdr);
                    lstCats.Add(curCat);
                    continue;
                }
                if (Regex.IsMatch(c.ToString(), ptnKey))
                {
                    Setting s = rdrReadSetting(rdr);
                    if (s.Value != null)
                    {
                        s.Category = curCat;
                        lstSettings.Add(s);
                    }
                    continue;
                }
                if (Regex.IsMatch(c.ToString(), ptnCommentStart))
                {
                    rdrReadComment(rdr);
                    continue;
                }

                // Must be whitespace, ignore it
                rdr.Read();
            }
        }
开发者ID:DiEvAl,项目名称:ftl-overdrive,代码行数:54,代码来源:SettingsFile.cs

示例11: ReadAKey

 public static bool ReadAKey(StringReader i_sr, out string key)
 {
     key = "";
     char ch = (char)i_sr.Peek();
     while (!IsEmptySpace(ch) && !IsToken(ch))
     {
         key += (char)i_sr.Read();
         ch = (char)i_sr.Peek();
     }
     return (key.Length > 0);
 }
开发者ID:OnionMoeCat,项目名称:UmbraChinaCK2,代码行数:11,代码来源:Reader.cs

示例12: Scan

        public IEnumerable<Token> Scan(string expression)
        {
            _reader = new StringReader(expression);

            while (_reader.Peek() != -1)
            {
                var c = (char)_reader.Peek();
                if (char.IsWhiteSpace(c))
                {
                    _reader.Read();
                    continue;
                }

                if (char.IsDigit(c) || c == '.')
                {
                    var value = ParseNumber();
                    yield return new NumberToken(value);
                }
                else if (c == '-')
                {
                    yield return new MinusToken();
                    _reader.Read();
                }
                else if (c == '+')
                {
                    yield return new PlusToken();
                    _reader.Read();
                }
                else if (c == '*')
                {
                    yield return new MultiplicationToken();
                    _reader.Read();
                }
                else if (c == '/')
                {
                    yield return new DivideToken();
                    _reader.Read();
                }
                else if (c == '(')
                {
                    yield return new OpenParenthesisToken();
                    _reader.Read();
                }
                else if (c == ')')
                {
                    yield return new ClosedParenthesisToken();
                    _reader.Read();
                }
                else
                    throw new Exception("Unknown character in expression: " + c);
            }
        }
开发者ID:FreeApophis,项目名称:ArithmeticParser,代码行数:52,代码来源:Tokenizer.cs

示例13: Prepare

        private void Prepare()
        {
            if (string.IsNullOrEmpty(_regex)) Error("Regex cannot be empty");
            var reader = new StringReader(_regex);
            var tmp = new StringBuilder(_regex.Length);

            bool range = false;
            while (reader.Peek() != -1)
            {
                char c = (char) reader.Read();
                int n = reader.Peek();
                bool escape = c == '\\' && ToEscape.Contains((char) n);
                if (escape) c = (char) reader.Read();

                bool start = !escape && c == '[';
                bool finish = !escape && c == ']';
                if (start) { range = true; tmp.Append('('); }
                else if (finish) { range = false; tmp.Remove(tmp.Length - 1, 1).Append(')'); }
                else if (!range) { tmp.AppendEscaped(escape, c); }
                else
                {
                    if (n == '-' && !escape)
                    {
                        reader.Read();
                        n = (char) reader.Peek();
                        for (char i = c; i < n; i++)
                            tmp.Append(i).Append('|');
                    }
                    else tmp.AppendEscaped(escape, c).Append('|');
                }
            }

            reader = new StringReader(tmp.ToString());
            tmp = new StringBuilder(tmp.Length * 2);
            bool printDot = false;
            while (reader.Peek() != -1)
            {
                char c = (char) reader.Read();
                int n = reader.Peek();
                bool escape = c == '\\' && ToEscape.Contains((char) n);
                if (escape) c = (char) reader.Read();

                if (printDot && !NotBefore.Contains(c) || printDot && escape)
                    tmp.Append('.');

                tmp.AppendEscaped(escape, c);
                printDot = !NotAfter.Contains(c) || escape;
            }

            _regex = tmp.ToString();
        }
开发者ID:surenkov,项目名称:UCP,代码行数:51,代码来源:InfixToPostfix.cs

示例14: TestPeekRead

	public void TestPeekRead() {
		StringReader reader = new StringReader( "Test String" );

		char c = (char)reader.Peek();
		Assert.AreEqual ('T', c, "A1");

		char read = (char)reader.Read();

		Assert.AreEqual ('T', read, "A2");

		c = (char)reader.Peek();

		Assert.AreEqual ('e', c, "A3");
	}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:StringReaderTest.cs

示例15: TestPeekRead

	public void TestPeekRead() {
		StringReader reader = new StringReader( "Test String" );

		char c = (char)reader.Peek();
		AssertEquals("A1", 'T', c );

		char read = (char)reader.Read();

		AssertEquals("A2", 'T', read );

		c = (char)reader.Peek();

		AssertEquals("A3", 'e', c );
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:14,代码来源:StringReaderTest.cs


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