CsvFieldIndexer: Fix calculation of offsets with unicode characters.
Fixes #4
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
@@ -10,15 +9,29 @@ namespace CsvLib
|
||||
private int _position;
|
||||
private readonly StringBuilder _sbBuffer = new StringBuilder();
|
||||
|
||||
private readonly Encoding _currentEncoding = Encoding.Default;
|
||||
|
||||
public BufferedTextReader(TextReader baseReader)
|
||||
{
|
||||
_baseReader = baseReader;
|
||||
if (baseReader is StreamReader streamReader)
|
||||
{
|
||||
_currentEncoding = streamReader.CurrentEncoding;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
_position++;
|
||||
int read = _baseReader.Read();
|
||||
if (read > 127)
|
||||
{
|
||||
int count = _currentEncoding.GetByteCount(((char)read).ToString());
|
||||
_position += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
_position++;
|
||||
}
|
||||
if (read != -1)
|
||||
{
|
||||
_sbBuffer.Append((char)read);
|
||||
@@ -26,11 +39,6 @@ namespace CsvLib
|
||||
return read;
|
||||
}
|
||||
|
||||
public override int Read(char[] buffer, int index, int count)
|
||||
{
|
||||
throw new NotImplementedException("Read buffered method on BufferedTextReader");
|
||||
}
|
||||
|
||||
public override int Peek()
|
||||
{
|
||||
return _baseReader.Peek();
|
||||
|
||||
Reference in New Issue
Block a user