public bool Read()
{
// read a record.
_fields = 0;
char ch = ReadChar();
if (ch == 0) return false;
while (ch != 0 && ch == '\r' || ch == '\n' || ch == ' ')
ch = ReadChar();
if (ch == 0) return false;
while (ch != 0 && ch != '\r' && ch != '\n') {
StringBuilder sb = AddField();
if (ch == '\'' || ch == '"') {
_quoteChar= ch;
char c = ReadChar();
bool done = false;
while (!done && c != 0) {
while (c != 0 && c != ch) { // scan literal.
sb.Append(c);
c = ReadChar();
}
if (c == ch) {
done = true;
char next = ReadChar(); // consume end quote
if (next == ch ) {
// it was an escaped quote sequence "" inside the literal
// so append a single " and consume the second end quote.
done = false;
sb.Append(next);
c = ReadChar();
if (_colDelim != 0 && c == _colDelim){
// bad form, but this is probably a record separator.
done = true;
}
} else if (_colDelim != 0 && next != _colDelim && next != 0 && next != ' ' && next != '\n' && next != '\r') {
// it was an un-escaped quote embedded inside a string literal
// in this case the quote is probably just part of the text so ignore it.
done = false;
sb.Append(c);
sb.Append(next);
c = ReadChar();
} else {
c = next;
}
}
}
ch = c;
}
else {
// skip whitespace
while (ch == ' ')
{
ch = ReadChar();
}
// scan number, date, time, float, etc.
while (ch != 0 && ch != '\n' && ch != '\r') {
if (ch == _colDelim || (_colDelim == '\0' && (ch == ',' || ch == ';' || ch == '\t' || ch == '|')))
break;
sb.Append(ch);
ch = ReadChar();
}
}
if (ch == _colDelim || (_colDelim == '\0' && (ch == ',' || ch == ';' || ch == '\t' || ch == '|'))){
_colDelim = ch;
ch = ReadChar();
if (ch == '\n' || ch == '\r') {
sb=AddField(); // blank field.
}
}
}
return true;
}