Skip to content

Commit 03afcb9

Browse files
committed
Modifid CsvReader to use a TextReader as the underlying character source so that UTF-8 and other file encodings are handled correctly.
1 parent f370b2b commit 03afcb9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Kajabity Tools/Csv/CsvReader.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public class CsvReader
167167
/// <summary>
168168
/// The input stream that characters are read and parsed from.
169169
/// </summary>
170-
private BufferedStream inStream = null;
170+
private TextReader inStream = null;
171171

172172
/// <summary>
173173
/// Stores the next character after it's been peeked until it is removed by NextChar().
@@ -194,7 +194,17 @@ public class CsvReader
194194
/// <param name="stream">The input stream to read from.</param>
195195
public CsvReader(Stream stream)
196196
{
197-
inStream = new BufferedStream(stream, BufferSize);
197+
inStream = new StreamReader(stream);
198+
}
199+
200+
/// <summary>
201+
/// Construct a CsvReader with a TextReader (e.g. StreamReader) allowing the caller
202+
/// to set the encoding, buffer size, etc.
203+
/// </summary>
204+
/// <param name="reader">an instance of a TextReader where the CSV data will be loaded from.</param>
205+
public CsvReader( TextReader reader )
206+
{
207+
inStream = reader;
198208
}
199209

200210
// ---------------------------------------------------------------------
@@ -426,7 +436,7 @@ private int NextChar()
426436
return savedChar;
427437
}
428438

429-
return inStream.ReadByte();
439+
return inStream.Read();
430440
}
431441

432442
/// <summary>
@@ -442,7 +452,7 @@ private int PeekChar()
442452
}
443453

444454
saved = true;
445-
return savedChar = inStream.ReadByte();
455+
return savedChar = inStream.Read();
446456
}
447457
}
448458
}

0 commit comments

Comments
 (0)