public void TestReadRecordRaw([Values(EndOfLine.CRLF, EndOfLine.LF, EndOfLine.CR)] EndOfLine eol) { const string ascii = "ASCII"; const string nonAscii = "日本語"; const string whitespace = " "; var withNewline = string.Format("hello{0}world", eol.AsNewline()); var csv = string.Format(" {0} {1} \"{2}\" \"{3}\" {0}{4}", ascii, nonAscii, whitespace, withNewline, eol.AsNewline()); var settings = new SpaceSeparatedTableReaderSettings() { RecordDelimiter = eol, }; using (var stringReader = new StringReader(csv)) using (var reader = new SpaceSeparatedTableReader(stringReader, settings)) { Assert.That(reader.MoveNext(), Is.True); var record = reader.Current; Assert.That(record, Is.Not.Null); Assert.That(record.FieldCount, Is.EqualTo(5)); Assert.That(record[0], Is.EqualTo(ascii)); Assert.That(record[1], Is.EqualTo(nonAscii)); Assert.That(record[2], Is.EqualTo(whitespace)); Assert.That(record[3], Is.EqualTo(withNewline)); Assert.That(record[0], Is.EqualTo(ascii)); Assert.That(reader.MoveNext(), Is.False); } }
private SpaceSeparatedTableReader(TextReader reader, SpaceSeparatedTableReaderSettings settings, bool disposed) { if (reader == null) { throw new ArgumentNullException("reader"); } settings = settings ?? new SpaceSeparatedTableReaderSettings(); this.reader = reader; this.newline = settings.RecordDelimiter.AsNewline(); this.newlineFirst = (int)this.newline[0]; this.quotation = settings.QuotationCharacter; this.disposed = disposed; }
/// <summary> /// Initializes a new <see cref="SpaceSeparatedTableReader"/> with the specified path to reading file. /// </summary> /// <param name="reader">The reader.</param> /// <param name="settings">The settings.</param> public SpaceSeparatedTableReader(TextReader reader, SpaceSeparatedTableReaderSettings settings = null) : this(reader, settings, true) { }
/// <summary> /// Initializes a new <see cref="SpaceSeparatedTableReader"/> with the specified file stream. /// </summary> /// <param name="stream">The file stream.</param> /// <param name="encoding">The encoding.</param> /// <param name="settings">The settings.</param> public SpaceSeparatedTableReader(Stream stream, Encoding encoding, SpaceSeparatedTableReaderSettings settings = null) : this(new StreamReader(stream, encoding), settings, false) { }
/// <summary> /// Initializes a new <see cref="SpaceSeparatedTableReader"/> with the specified path to reading file. /// </summary> /// <param name="path">The path to file to read.</param> /// <param name="settings">The settings.</param> public SpaceSeparatedTableReader(string path, SpaceSeparatedTableReaderSettings settings = null) : this(new StreamReader(path), settings, false) { }