public string ReadValue(TextFileContext context)
 {
     Ensure.ArgumentNotNull(context, "context");
     context.EnsureNotAtEndOfLine(size);
     context.CurrentLinePosition += size;
     return context.CurrentLine.Substring(context.CurrentLinePosition - size, size);
 }
 public void When_quoted_field_contains_escaped_quotes_then_read_quoted_value_excluding_escape_token()
 {
     context = new TextFileContextStub("Testing 'quoted with ''escaped'' part'");
     context.CurrentLinePosition = 8;
     var value = field.ReadValue(context);
     Assert.AreEqual("quoted with 'escaped' part", value);
     Assert.AreEqual(38, context.CurrentLinePosition);
 }
Пример #3
0
 public string ReadValue(TextFileContext context)
 {
     Ensure.ArgumentNotNull(context, "context");
     context.EnsureNotAtEndOfLine();
     // TODO: Test performance of this under load, may need to switch to unsafe code
     int startPosition = context.CurrentLinePosition;
     bool isQuoted = false;
     int endExcess = 0;
     var quotePositions = new List<int>();
     var escapePositions = new List<int>();
     while (!context.Eol)
     {
         if (context.IsTokenAtCurrentPosition(escapedQuoteToken))
         {
             escapePositions.Add(context.CurrentLinePosition);
             context.CurrentLinePosition += escapedQuoteToken.Length;
             continue;
         }
         if (context.IsTokenAtCurrentPosition(quoteToken))
         {
             quotePositions.Add(context.CurrentLinePosition);
             context.CurrentLinePosition += quoteToken.Length;
             isQuoted = !isQuoted;
             continue;
         }
         var foundSeparator = isQuoted ? null : delimiters
             .Where(s => context.IsTokenAtCurrentPosition(s))
             .FirstOrDefault();
         if (foundSeparator != null)
         {
             context.CurrentLinePosition += foundSeparator.Length;
             endExcess = foundSeparator.Length;
             break;
         }
         ++context.CurrentLinePosition;
     }
     var value = context.CurrentLine.Substring(startPosition, 
         context.CurrentLinePosition - startPosition - endExcess);
     if (quotePositions.Any())
         value = RemoveTokens(value, quoteToken, quotePositions.Select(p => p - startPosition));
     if (escapePositions.Any())
         value = RemoveTokens(value, escapeToken, escapePositions.Select(p => p - startPosition));
     return value;
 }
 public void Initialize()
 {
     context = new TextFileContextStub("Here is a ``quoted value`` and ``another one``. ");
     field = new DelimitedField(new[] { " " }, "``", null);
 }
 public void Initialize()
 {
     context = new TextFileContextStub("Hello world!");
     field = new FixedWidthField(5);
 }
 public void Initialize()
 {
     context = new TextFileContextStub("Hi, I''m Ray 'Boom Boom' Mancini");
     field = new DelimitedField(new[] { " " }, "'", "'");
 }
 internal EndOfLineException(TextFileContext context, int characterCount = 1,
     string message = DefaultMessage, Exception innerException = null)
     : base(context, message, innerException)
 {
     this.CharacterCount = characterCount;
 }
Пример #8
0
 internal TextException(TextFileContext context, string message = DefaultMessage,
     Exception innerException = null)
     : this(context.FileName, context.CurrentLineNumber, context.CurrentLinePosition, 
     context.CurrentLine, message, innerException)
 {
 }
 internal EndOfFileException(TextFileContext context, string message = DefaultMessage,
     Exception innerException = null)
     : base(context, message, innerException)
 {
 }
 public void Initialize()
 {
     context = new TextFileContextStub("One, two, three||four");
     field = new DelimitedField(new[] { ",", " ", "||" }, null, null);
 }