예제 #1
0
 /// <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);
 })
 {
 }
예제 #2
0
        public void TestSimpleRead()
        {
            var reader = new InputTextReader(CONTENT);

            for (var i = 0; i < CONTENT.Length; i++)
            {
                Assert.Equal(reader.Read(), CONTENT[i]);
            }
        }
예제 #3
0
        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]);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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]);
        }
예제 #6
0
 /// <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));
 }
예제 #7
0
        /// <summary>
        /// Removes all leading and trailing dots; replaces consecutive dots with a single dot
        /// Ex: ".lalal.....com." -&gt; "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());
        }
예제 #8
0
 public string readLine()
 {
     return(InputTextReader.ReadLine());
 }