/// <summary> /// Constructor that provides the default throw-exception callback action upon /// parse error. /// </summary> /// <param name="reader">Provides the text of the report.</param> /// <param name="reportName">An arbitrary name given to this report.</param> public AwReport(InputTextReader reader, string reportName) : this(reader, reportName, (colVal, record) => { throw new InvalidOperationException("Could not set the member " + colVal.ColName + " with value " + colVal.Value); }) { }
public void TestSimpleRead() { var reader = new InputTextReader(CONTENT); for (var i = 0; i < CONTENT.Length; i++) { Assert.Equal(reader.Read(), CONTENT[i]); } }
public void TestSeek() { var reader = new InputTextReader(CONTENT); reader.Seek(4); Assert.Equal(reader.Read(), CONTENT[4]); reader.Seek(1); Assert.Equal(reader.Read(), CONTENT[1]); }
public void TestEof() { var reader = new InputTextReader(CONTENT); for (var i = 0; i < CONTENT.Length - 1; i++) { reader.Read(); } Assert.False(reader.Eof()); reader.Read(); Assert.True(reader.Eof()); }
public void TestGoBack() { var reader = new InputTextReader(CONTENT); Assert.Equal(reader.Read(), CONTENT[0]); reader.GoBack(); Assert.Equal(reader.Read(), CONTENT[0]); Assert.Equal(reader.Read(), CONTENT[1]); Assert.Equal(reader.Read(), CONTENT[2]); reader.GoBack(); reader.GoBack(); Assert.Equal(reader.Read(), CONTENT[1]); Assert.Equal(reader.Read(), CONTENT[2]); }
/// <summary> /// Constructor. /// </summary> /// <param name="reader">Provides the text of the report.</param> /// <param name="reportName">An arbitrary name given to this report.</param> /// <param name="onError">A callback action that is used when there is /// an error in parsing an attribute from the report.</param> public AwReport(InputTextReader reader, string reportName, Action <ColumnValuePair, A> onError) { if (reader == null) { throw new ArgumentNullException("The input text reader cannot be null."); } ReportParserUtils.ValidatePocoType <A>(); this.ReportName = reportName; this.reader = reader; this.OnError = onError; ReportParserUtils.GetColumnNamesFromPocoType <A>() .ToList().ForEach(name => colNames.Add(name)); }
/// <summary> /// Removes all leading and trailing dots; replaces consecutive dots with a single dot /// Ex: ".lalal.....com." -> "lalal.com" /// </summary> /// <param name="host"></param> /// <returns></returns> public static string RemoveExtraDots(string host) { var stringBuilder = new StringBuilder(); var reader = new InputTextReader(host); while (!reader.Eof()) { var curr = reader.Read(); stringBuilder.Append(curr); if (curr == '.') { var possibleDot = curr; while (possibleDot == '.' && !reader.Eof()) { possibleDot = reader.Read(); } if (possibleDot != '.') { stringBuilder.Append(possibleDot); } } } if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] == '.') { stringBuilder.Remove(stringBuilder.Length - 1, 1); } if (stringBuilder.Length > 0 && stringBuilder[0] == '.') { stringBuilder.Remove(0, 1); } return(stringBuilder.ToString()); }
public string readLine() { return(InputTextReader.ReadLine()); }