in util/src/main/java/com/epam/deltix/util/csvx/CSVXReader.java [148:320]
public boolean nextLine () throws IOException {
if (mEOF)
return (false);
mBuffer.setLength (0);
mInclStartIndexes.clear ();
mExclEndIndexes.clear ();
int state = BEGIN;
int start = 0;
for (;;) {
int ch = mReader.read ();
if (mLastCharWasCR && ch == 10)
continue;
mLastCharWasCR = ch == 13;
switch (state) {
case BEGIN:
mLineStartPosition =
mInputStream == null ? -1 : mInputStream.getNumBytesRead () - 1;
if (ch == mDelimiter) {
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
state = COMMA;
}
else
switch (ch) {
case -1:
mEOF = true;
return (false);
case 10:
case 13:
mLineNumber++;
return (true);
case '"':
start = mBuffer.length ();
state = QUOTED_CELL;
break;
default:
start = mBuffer.length ();
mBuffer.append ((char) ch);
state = UNQUOTED_CELL;
break;
}
break;
case COMMA:
if (ch == mDelimiter) {
mInclStartIndexes.add (0);
mExclEndIndexes.add (0);
}
else
switch (ch) {
case -1:
mEOF = true;
mInclStartIndexes.add (0);
mExclEndIndexes.add (0);
return (true);
case 10:
case 13:
mLineNumber++;
mInclStartIndexes.add (0);
mExclEndIndexes.add (0);
return (true);
case '"':
start = mBuffer.length ();
state = QUOTED_CELL;
break;
default:
start = mBuffer.length ();
mBuffer.append ((char) ch);
state = UNQUOTED_CELL;
break;
}
break;
case QUOTED_CELL:
switch (ch) {
case -1:
throw new EOFException (
mDiagPrefix + "Unterminated cell at end of file"
);
case 10:
case 13:
mLineNumber++;
mBuffer.append ('\n');
break;
case '"':
state = QUOTED_QUOTE;
break;
default:
mBuffer.append ((char) ch);
break;
}
break;
case UNQUOTED_CELL:
if (ch == mDelimiter) {
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
state = COMMA;
}
else
switch (ch) {
case -1:
mEOF = true;
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
return (true);
case 10:
case 13:
mLineNumber++;
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
state = BEGIN;
return (true);
default:
mBuffer.append ((char) ch);
break;
}
break;
case QUOTED_QUOTE:
if (ch == mDelimiter) {
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
state = COMMA;
}
else
switch (ch) {
case -1:
mEOF = true;
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
return (true);
case 10:
case 13:
mLineNumber++;
mInclStartIndexes.add (start);
mExclEndIndexes.add (mBuffer.length ());
state = BEGIN;
return (true);
case '"':
mBuffer.append ('"');
state = QUOTED_CELL;
break;
default:
mBuffer.append ((char) ch);
state = UNQUOTED_CELL;
break;
}
break;
}
}
}