• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Util.StringReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



StringReader类属于Edu.Wisc.Forest.Flel.Util命名空间,在下文中一共展示了StringReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ReadMethod_NumWithWhiteSpace

 public void ReadMethod_NumWithWhiteSpace()
 {
     StringReader reader = new StringReader(" \t -1,234 \n ");
     inputVar.ReadValue(reader);
     Assert.AreEqual(-1234, inputVar.Value.Actual);
     Assert.AreEqual("-1,234", inputVar.Value.String);
     Assert.AreEqual(3, inputVar.Index);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Model,代码行数:8,代码来源:EffectiveSeedDist_Test.cs


示例2: IntVar_MinusDigits

 public void IntVar_MinusDigits()
 {
     StringReader reader = new StringReader("-1234");
     intVar.ReadValue(reader);
     Assert.AreEqual(-1234, intVar.Value.Actual);
     Assert.AreEqual("-1234", intVar.Value.String);
     Assert.AreEqual(0, intVar.Index);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:8,代码来源:InputVar_Int_Test.cs


示例3: ReadMethod_PlusDigits

 public void ReadMethod_PlusDigits()
 {
     StringReader reader = new StringReader("+1,234");
     inputVar.ReadValue(reader);
     Assert.AreEqual(1234, inputVar.Value.Actual);
     Assert.AreEqual("+1,234", inputVar.Value.String);
     Assert.AreEqual(0, inputVar.Index);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Model,代码行数:8,代码来源:EffectiveSeedDist_Test.cs


示例4: IntVar_LeadingWhiteSpace

 public void IntVar_LeadingWhiteSpace()
 {
     StringReader reader = new StringReader(" \t -1234");
     intVar.ReadValue(reader);
     Assert.AreEqual(-1234, intVar.Value.Actual);
     Assert.AreEqual("-1234", intVar.Value.String);
     Assert.AreEqual(3, intVar.Index);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:8,代码来源:InputVar_Int_Test.cs


示例5: ReadYear

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

        /// <summary>
        /// Reads a year or a year expression.
        /// </summary>
        /// A year expression is an expression that refers to a year by its
        /// relation to either the scenario's starting or ending year.  The
        /// valid format for a year expression is:
        /// 
        /// <pre>
        ///    start
        ///    start+<i>integer</i>
        ///    end
        ///    end-<i>integer</i>
        /// </pre>
        /// </remarks>
        public static InputValue<int> ReadYear(StringReader reader,
                                               out int      index)
        {
            CheckForInitialization();
            TextReader.SkipWhitespace(reader);
            index = reader.Index;
            string word = TextReader.ReadWord(reader);
            return new InputValue<int>(ParseYear(word), word);
        }
开发者ID:LANDIS-II-Foundation,项目名称:Extension-Century-Succession,代码行数:25,代码来源:InputValidation.cs


示例6: PrintInputVarException

 //---------------------------------------------------------------------
 private void PrintInputVarException(string input)
 {
     try {
         StringReader reader = new StringReader(input);
         seedAlgVar.ReadValue(reader);
     }
     catch (InputVariableException exc) {
         Data.Output.WriteLine(exc.Message);
         throw exc;
     }
 }
开发者ID:LANDIS-II-Foundation,项目名称:Library-Succession,代码行数:12,代码来源:SeedingAlgorithmsUtil_Test.cs


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: Read

		/// <summary>
		/// Reads a plug-in name from a text reader and returns the
		/// information for the plug-in.
		/// </summary>
		public static InputValue<Edu.Wisc.Forest.Flel.Util.PlugIns.Info> Read(StringReader reader,
	                                                                          out int      index)
		{
			ReadMethod<string> strReadMethod = InputValues.GetReadMethod<string>();
			InputValue<string> name = strReadMethod(reader, out index);
			if (name.Actual.Trim(null) == "")
				throw new InputValueException(name.Actual,
				                              name.String + " is not a valid plug-in name.");
			Edu.Wisc.Forest.Flel.Util.PlugIns.Info info = (Edu.Wisc.Forest.Flel.Util.PlugIns.Info) PlugIns.Manager.GetInfo(name.Actual);
			if (info == null)
				throw new InputValueException(name.Actual,
				                              "No plug-in with the name \"{0}\".",
				                              name.Actual);
			return new InputValue<Edu.Wisc.Forest.Flel.Util.PlugIns.Info>(info, name.Actual);
		}
开发者ID:LANDIS-II-Foundation,项目名称:Libraries,代码行数:19,代码来源:PlugInInfo.cs


示例12: 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


示例13: Read

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

		/// <summary>
		/// Reads a plug-in name from a text reader and returns the
		/// information for the plug-in.
		/// </summary>
		public static InputValue<PlugIns.PlugInInfo> Read(StringReader reader,
	                                                      out int      index)
		{
			ReadMethod<string> strReadMethod = InputValues.GetReadMethod<string>();
			InputValue<string> name = strReadMethod(reader, out index);
			if (name.Actual.Trim(null) == "")
				throw new InputValueException(name.Actual,
				                              name.String + " is not a valid plug-in name.");
			PlugIns.PlugInInfo info = installedPlugIns[name.Actual];
			if (info == null)
				throw new InputValueException(name.Actual,
				                              "No plug-in with the name \"{0}\".",
				                              name.Actual);
			return new InputValue<PlugIns.PlugInInfo>(info, name.Actual);
		}
开发者ID:LANDIS-II-Foundation,项目名称:Libraries,代码行数:21,代码来源:PlugInInfo.cs


示例14: 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


示例15: ReadMethod

 //---------------------------------------------------------------------
 ///    <summary>
 /// Reads an integer input value for an effective seed-dispersal
 /// distance.
 /// </summary>
 /// <param name="reader">
 /// The string reader from which the input value is read.
 /// </param>
 /// <param name="index">
 /// The starting index in the reader's input stream where the input
 /// value was located.
 /// </param>
 /// <remarks>
 /// This method uses the registered ReadMethod for integer values.
 /// The input value "uni" is treated specially, and yield an integer
 /// input value equal to the Universal constant.
 /// </remarks>
 public static InputValue<int> ReadMethod(StringReader reader,
     out int      index)
 {
     ReadMethod<int> intRead = InputValues.GetReadMethod<int>();
     try {
         return intRead(reader, out index);
     }
     catch (InputValueException exc) {
         if (exc.Value == UniversalAsString) {
             index = reader.Index - exc.Value.Length;
             return new InputValue<int>(Universal, exc.Value);
         }
         else if (exc.Message.Contains("outside the range")) {
             //    Overflow exception with integer value
             throw;
         }
         else {
             string message = string.Format("\"{0}\" is not a valid integer or \"{1}\"",
                                            exc.Value, UniversalAsString);
             throw new InputValueException(exc.Value, message);
         }
     }
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Model,代码行数:40,代码来源:EffectiveSeedDist.cs


示例16: ReadAgeOrRange

        //---------------------------------------------------------------------
        /// <summary>
        /// Reads a cohort age or a range of ages (format: age-age) followed
        /// by an optional percentage for partial thinning.
        /// </summary>
        /// <remarks>
        /// The optional percentage is bracketed by parenthesis.
        /// </remarks>
        public static InputValue<AgeRange> ReadAgeOrRange(StringReader reader,
            out int      index)
        {
            TextReader.SkipWhitespace(reader);
            index = reader.Index;

            string word = ReadWord(reader, '(');
            if (word == "")
                throw new InputValueException();  // Missing value

            AgeRange ageRange = AgeRangeParsing.ParseAgeOrRange(word);

            //  Does a percentage follow?
            TextReader.SkipWhitespace(reader);
            if (reader.Peek() == '(') {
                int ignore;
                InputValue<Percentage> percentage = ReadPercentage(reader, out ignore);
                percentages[ageRange.Start] = percentage;
            }

            return new InputValue<AgeRange>(ageRange, word);
        }
开发者ID:LANDIS-II-Foundation,项目名称:Library-Biomass-Harvest,代码行数:30,代码来源:PartialThinning.cs


示例17: 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


示例18: Read_SingleQuote_TextNoEnd

 public void Read_SingleQuote_TextNoEnd()
 {
     StringReader reader = new StringReader("'Four score and ");
     PrintInputVarException(reader);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Core-Utilities-Library,代码行数:5,代码来源:InputVar_String_Test.cs


示例19: ReadInputVar

 //---------------------------------------------------------------------
 private void ReadInputVar(string input)
 {
     StringReader reader = new StringReader(input);
     seedAlgVar.ReadValue(reader);
 }
开发者ID:LANDIS-II-Foundation,项目名称:Library-Succession,代码行数:6,代码来源:SeedingAlgorithmsUtil_Test.cs


示例20: ReadAgeOrRange

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

        /// <summary>
        /// Reads a cohort age or a range of ages (format: age-age) followed
        /// by an optional percentage for partial thinning.
        /// </summary>
        /// <remarks>
        /// The optional percentage is bracketed by parenthesis.
        /// </remarks>
        public static InputValue<AgeRange> ReadAgeOrRange(StringReader reader,
                                                          out int      index)
        {
            TextReader.SkipWhitespace(reader);
            index = reader.Index;

            string word = ReadWord(reader, '(');
            if (word == "")
                throw new InputValueException();  // Missing value

            AgeRange ageRange = BaseHarvest.InputParametersParser.ParseAgeOrRange(word);

            //  Does a percentage follow?
            TextReader.SkipWhitespace(reader);
            if (reader.Peek() == '(') {
                int ignore;
                InputValue<Percentage> percentage = ReadPercentage(reader, out ignore);
                if (ReadAgeOrRangeEvent != null)
                    ReadAgeOrRangeEvent(ageRange, percentage.Actual);
            }
            else {
                if (ReadAgeOrRangeEvent != null)
                    ReadAgeOrRangeEvent(ageRange, null);
            }

            return new InputValue<AgeRange>(ageRange, word);
        }
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:36,代码来源:PartialThinning.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ekona.sFile类代码示例发布时间:2022-05-24
下一篇:
C# Util.Percentage类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap