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


C# StringReader.Peek方法代码示例

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


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

示例1: ReadAgeOrRange_RangePercentage

 public void ReadAgeOrRange_RangePercentage()
 {
     StringReader reader = new StringReader("30-75(10%)");
     int index;
     eventHandlerCalled = false;
     expectedRange = new AgeRange(30, 75);
     expectedPercentage = Percentage.Parse("10%");
     InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index);
     Assert.IsTrue(eventHandlerCalled);
     Assert.AreEqual(0, index);
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:12,代码来源:PartialThinning_Test.cs

示例2: ReadAgeOrRange_RangeWhitespacePercentage

 public void ReadAgeOrRange_RangeWhitespacePercentage()
 {
     StringReader reader = new StringReader(" 1-100 (22.2%)Hi");
     int index;
     eventHandlerCalled = false;
     expectedRange = new AgeRange(1, 100);
     expectedPercentage = Percentage.Parse("22.2%");
     InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index);
     Assert.IsTrue(eventHandlerCalled);
     Assert.AreEqual(1, index);
     Assert.AreEqual('H', reader.Peek());
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:12,代码来源:PartialThinning_Test.cs

示例3: ReadPercentage

        //---------------------------------------------------------------------

        /// <summary>
        /// Reads a percentage for partial thinning of a cohort age or age
        /// range.
        /// </summary>
        /// <remarks>
        /// The percentage is bracketed by parentheses.
        /// </remarks>
        public static InputValue<Percentage> ReadPercentage(StringReader reader,
                                                            out int      index)
        {
            TextReader.SkipWhitespace(reader);
            index = reader.Index;

            //  Read left parenthesis
            int nextChar = reader.Peek();
            if (nextChar == -1)
                throw new InputValueException();  // Missing value
            if (nextChar != '(')
                throw MakeInputValueException(TextReader.ReadWord(reader),
                                              "Value does not start with \"(\"");
            StringBuilder valueAsStr = new StringBuilder();
            valueAsStr.Append((char) (reader.Read()));

            //  Read whitespace between '(' and percentage
            valueAsStr.Append(ReadWhitespace(reader));

            //  Read percentage
            string word = ReadWord(reader, ')');
            if (word == "")
                throw MakeInputValueException(valueAsStr.ToString(),
                                              "No percentage after \"(\"");
            valueAsStr.Append(word);
            Percentage percentage;
            try {
                percentage = Percentage.Parse(word);
            }
            catch (System.FormatException exc) {
                throw MakeInputValueException(valueAsStr.ToString(),
                                              exc.Message);
            }
            if (percentage < 0.0 || percentage > 1.0)
                throw MakeInputValueException(valueAsStr.ToString(),
                                              string.Format("{0} is not between 0% and 100%", word));

            //  Read whitespace and ')'
            valueAsStr.Append(ReadWhitespace(reader));
            char? ch = TextReader.ReadChar(reader);
            if (! ch.HasValue)
                throw MakeInputValueException(valueAsStr.ToString(),
                                              "Missing \")\"");
            valueAsStr.Append(ch.Value);
            if (ch != ')')
                throw MakeInputValueException(valueAsStr.ToString(),
                                              string.Format("Value ends with \"{0}\" instead of \")\"", ch));

            return new InputValue<Percentage>(percentage, valueAsStr.ToString());
        }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:59,代码来源:PartialThinning.cs

示例4: NonEmptyString

 public void NonEmptyString()
 {
     string str = "Hello World!";
     StringReader reader = new StringReader(str);
     int expectedIndex = 0;
     foreach (char expectedCh in str) {
         Assert.AreEqual(expectedIndex, reader.Index);
         int i = reader.Read();
         Assert.IsTrue(i != -1);
         Assert.AreEqual(expectedCh, (char) i);
         expectedIndex++;
     }
     Assert.AreEqual(expectedIndex, reader.Index);
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:15,代码来源:StringReader_Test.cs

示例5: ReadBlock

        public void ReadBlock()
        {
            string str = "Four score and seven years ago ...";
            StringReader reader = new StringReader(str);
            char[] buffer = new char[str.Length];
            int blockSize = 5;

            for (int bufferIndex = 0; bufferIndex < buffer.Length; bufferIndex += blockSize) {
                Assert.AreEqual(bufferIndex, reader.Index);
                int countToRead;
                if (bufferIndex + blockSize > buffer.Length)
                    countToRead = buffer.Length - bufferIndex;
                else
                    countToRead = blockSize;
                Assert.AreEqual(countToRead, reader.Read(buffer, bufferIndex,
                                                         countToRead));
            }
            Assert.AreEqual(str.Length, reader.Index);
            Assert.AreEqual(-1, reader.Peek());
            Assert.AreEqual(str, new string(buffer));
        }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:21,代码来源:StringReader_Test.cs

示例6: EmptyString

 public void EmptyString()
 {
     StringReader reader = new StringReader("");
     Assert.AreEqual(0, reader.Index);
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:6,代码来源:StringReader_Test.cs

示例7: ReadWhitespace

 //---------------------------------------------------------------------
 /// <summary>
 /// Reads whitespace from a string reader.
 /// </summary>
 public static string ReadWhitespace(StringReader reader)
 {
     StringBuilder whitespace = new StringBuilder();
     int i = reader.Peek();
     while (i != -1 && char.IsWhiteSpace((char) i)) {
         whitespace.Append((char) reader.Read());
         i = reader.Peek();
     }
     return whitespace.ToString();
 }
开发者ID:LANDIS-II-Foundation,项目名称:Library-Biomass-Harvest,代码行数:14,代码来源:PartialThinning.cs

示例8: ReadForestTypeTable

        //----------------------------------------------------------------------

        //  Need to include a copy of this method because it modifies an
        //  instance member "rankingMethod" in the original version.  Bad
        //  design; the ranking method should be passed as a parameter.
        
        protected void ReadForestTypeTable(IStandRankingMethod rankingMethod)
        {
            int optionalStatements = 0;
            
            //check if this is the ForestTypeTable
            if (CurrentName == Names.ForestTypeTable) {
                ReadName(Names.ForestTypeTable);

                //fresh input variables for table
                InputVar<string> inclusionRule = new InputVar<string>("Inclusion Rule");
                InputVar<AgeRange> age_range = new InputVar<AgeRange>("Age Range", ParseAgeOrRange);
                InputVar<string> percentOfCells = new InputVar<string>("PercentOfCells");  //as a string so it can include keyword 'highest'
                InputVar<string> speciesName = new InputVar<string>("Species");
                
                
                //list for each rule- each line is a separate rule
                List<InclusionRule> rule_list = new List<InclusionRule>();              
                //keep reading until no longer in the ForestTypeTable
                while (! AtEndOfInput && !namesThatFollowForestType.Contains(CurrentName)) {
                    StringReader currentLine = new StringReader(CurrentLine);

                    //  inclusionRule column
                    ReadValue(inclusionRule, currentLine);

                    //verify inclusion rule = 'optional', 'required', or 'forbidden'
                    if (inclusionRule.Value.Actual != "Optional" && inclusionRule.Value.Actual != "Required"
                                    && inclusionRule.Value.Actual != "Forbidden") {
                        string[] ic_list = new string[]{"Valid Inclusion Rules:",
                                                                           "    Optional",
                                                                           "    Required",
                                                                           "    Forbidden"};
                        throw new InputValueException(CurrentName, CurrentName + " is not a valid inclusion rule.",
                                                  new MultiLineText(ic_list));
                    }

                    if (inclusionRule.Value.Actual == "Optional")
                        optionalStatements++;
                    
                    
                    TextReader.SkipWhitespace(currentLine);
                    ReadValue(age_range, currentLine);

                    //percentage column
                    TextReader.SkipWhitespace(currentLine);
                    ReadValue(percentOfCells, currentLine);
                    //PlugIn.ModelCore.UI.WriteLine("percentOfCells = {0}", percentOfCells.Value.String);
                    //cannot validate until parsing is done.  will do this in the inclusionRule constructor

                    //a list in case there are multiple species on this line
                    List<string> species_list = new List<string>();
                    //add each species to this rule's species list
                    TextReader.SkipWhitespace(currentLine);
                    while (currentLine.Peek() != -1) {
                        //species column (build list)
                        
                        ReadValue(speciesName, currentLine);
                        string name = speciesName.Value.String;
                        
                        ISpecies species = GetSpecies(new InputValue<string>(name, speciesName.Value.String));
                        if (species_list.Contains(species.Name))
                            throw NewParseException("The species {0} appears more than once.", species.Name);
                        species_list.Add(species.Name);

                        //species_list.Add(species.Value.String);
                        TextReader.SkipWhitespace(currentLine);
                    }

                    //add this new inclusion rule (by parameters)  to the requirement
                    rule_list.Add(new InclusionRule(inclusionRule.Value.String,
                                                    age_range.Value.Actual,
                                                    percentOfCells.Value.String,
                                                    species_list));
                    
                    GetNextLine();
                }
                //create a new requirement with this list of rules
                IRequirement inclusionRequirement = new InclusionRequirement(rule_list);
                //add this requirement to the ranking method
                rankingMethod.AddRequirement(inclusionRequirement);
            }
            
            if(optionalStatements > 0 && optionalStatements < 2)
                throw new InputValueException(CurrentName, "If there are optional statements, there must be more than one",
                                                  "ForestTypeTable");
            
        }
开发者ID:LANDIS-II-Foundation,项目名称:Extensions-Disturbance,代码行数:92,代码来源:InputParametersParser.cs

示例9: Read_MultipleWords

 public void Read_MultipleWords()
 {
     string[] words = new string[] { "987.01", ".'.", "x-y*z^2", @"C:\some\Path\to\a\file.ext" };
     StringReader reader = new StringReader(string.Join(" ", words));
     foreach (string word in words) {
         strVar.ReadValue(reader);
         Assert.AreEqual(word, strVar.Value.Actual);
     }
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:10,代码来源:InputVar_String_Test.cs

示例10: GetReadMethod_Byte_StringOfBytes

 public void GetReadMethod_Byte_StringOfBytes()
 {
     StringReader reader = new StringReader(valuesAsStr);
     int prevIndex = -1;
     foreach (byte b in values) {
         int index;
         InputValue<byte> result = byteReadMethod(reader, out index);
         Assert.AreEqual(b, result.Actual);
         Assert.IsTrue(index > prevIndex);
         prevIndex = index;
     }
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:13,代码来源:InputValues_Test.cs

示例11: ReadAgeOrRange_AgeWhitespacePercentage

 public void ReadAgeOrRange_AgeWhitespacePercentage()
 {
     StringReader reader = new StringReader("66 ( 50% )\t");
     int index;
     eventHandlerCalled = false;
     expectedRange = new AgeRange(66, 66);
     expectedPercentage = Percentage.Parse("50%");
     InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index);
     Assert.IsTrue(eventHandlerCalled);
     Assert.AreEqual(0, index);
     Assert.AreEqual('\t', reader.Peek());
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:12,代码来源:PartialThinning_Test.cs

示例12: ReadWord_Empty

 public void ReadWord_Empty()
 {
     StringReader reader = new StringReader("");
     string word = PartialThinning.ReadWord(reader, '(');
     Assert.AreEqual("", word);
     Assert.AreEqual(-1, reader.Peek());
     Assert.AreEqual(0, reader.Index);
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:8,代码来源:PartialThinning_Test.cs

示例13: ReadPercentage_Whitespace

 public void ReadPercentage_Whitespace()
 {
     StringReader reader = new StringReader("( 55.5%\t)");
     int index;
     InputValue<Percentage> percentage = PartialThinning.ReadPercentage(reader, out index);
     Assert.IsNotNull(percentage);
     Assert.AreEqual("( 55.5%\t)", percentage.String);
     Assert.AreEqual(0.555, (double) (percentage.Actual));
     Assert.AreEqual(0, index);
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:11,代码来源:PartialThinning_Test.cs

示例14: ReadPercentage_WhitespaceAfterLParen

 public void ReadPercentage_WhitespaceAfterLParen()
 {
     StringReader reader = new StringReader("( 8%)a");
     int index;
     InputValue<Percentage> percentage = PartialThinning.ReadPercentage(reader, out index);
     Assert.IsNotNull(percentage);
     Assert.AreEqual("( 8%)", percentage.String);
     Assert.AreEqual(0.08, (double) (percentage.Actual));
     Assert.AreEqual(0, index);
     Assert.AreEqual('a', reader.Peek());
 }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:11,代码来源:PartialThinning_Test.cs

示例15: CheckReadResults

 //---------------------------------------------------------------------
 private void CheckReadResults(string readerInitVal,
     string expectedReadResult)
 {
     StringReader reader = new StringReader(readerInitVal);
     int index;
     InputValue<string> val = String.Read(reader, out index);
     Assert.AreEqual(expectedReadResult, val.Actual);
     Assert.AreEqual(-1, reader.Peek());
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:10,代码来源:String_Test.cs


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