本文整理汇总了C#中Edu.Wisc.Forest.Flel.Util.StringReader类的典型用法代码示例。如果您正苦于以下问题:C# StringReader类的具体用法?C# StringReader怎么用?C# StringReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringReader类属于Edu.Wisc.Forest.Flel.Util命名空间,在下文中一共展示了StringReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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));
}
示例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);
}
}
}