Class CsvReaderVisitorBase
Base class for listeners that process a stream of RFC 4180 (CSV) tokens from an instance of CsvTokenizer.
Inherited Members
Namespace: Cursively
Assembly: Cursively.dll
Syntax
public abstract class CsvReaderVisitorBase
Remarks
Remarks on the documentation of individual abstract methods indicate when the tokenizer is legally allowed to call that method.
Fields
| Improve this Doc View SourceNull
An implementation of CsvReaderVisitorBase that does nothing when it sees any of the tokens.
Declaration
public static readonly CsvReaderVisitorBase Null
Field Value
Type | Description |
---|---|
CsvReaderVisitorBase |
Methods
| Improve this Doc View SourceVisitEndOfField(ReadOnlySpan<Byte>)
Visits the last part of a field's data.
Declaration
public abstract void VisitEndOfField(ReadOnlySpan<byte> chunk)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<Byte> | chunk | The data from the last part of the field. |
Remarks
This method may be called at any time.
Any method except VisitNonstandardQuotedField(), including this one, may be called directly after a call to this method.
This method may be called without a preceding VisitPartialFieldContents(ReadOnlySpan<Byte>) call, if the field's entire data is contained within the given chunk.
VisitEndOfRecord()
Notifies that all fields in the current record have been visited.
Declaration
public abstract void VisitEndOfRecord()
Remarks
This method may only be called as the very next method that gets called after a call to VisitEndOfField(ReadOnlySpan<Byte>).
Only VisitPartialFieldContents(ReadOnlySpan<Byte>) and VisitEndOfField(ReadOnlySpan<Byte>) may be called directly after a call to this method.
VisitNonstandardQuotedField()
Notifies that the current field contains double-quote characters that do not comply with RFC 4180, and so it is being processed according to this library's extra rules.
The default behavior of this method is to do nothing. Subclasses may wish to override to add warnings / errors when processing streams that do not follow RFC 4180 and are therefore in danger of being processed differently than other tools.
Declaration
public virtual void VisitNonstandardQuotedField()
Remarks
This method may only be called as the very next method that gets called after a call to VisitPartialFieldContents(ReadOnlySpan<Byte>), and only at most once per field (i.e., once it is called, it may not be called again until a VisitEndOfField(ReadOnlySpan<Byte>) call brings the tokenizer back to a state where RFC 4180 rules are expected).
Only VisitPartialFieldContents(ReadOnlySpan<Byte>) and VisitEndOfField(ReadOnlySpan<Byte>) may be called directly after a call to this method.
The last byte in the preceding VisitPartialFieldContents(ReadOnlySpan<Byte>) call's chunk will be the specific byte that was unexpected; all bytes before it were legal under RFC 4180. So if this event is being raised because the tokenizer found a double-quote in a field that did not start with a double-quote, then VisitPartialFieldContents(ReadOnlySpan<Byte>) was previously called with a chunk that ended with that double-quote. If it's being raised because a double-quote was found in a quoted field that was not immediately followed by a double-quote, delimiter, or line ending, then VisitPartialFieldContents(ReadOnlySpan<Byte>) was previously called with a chunk that ended with whichever byte immediately followed the double-quote that ended the quoted part of the quoted field data.
VisitPartialFieldContents(ReadOnlySpan<Byte>)
Visits part of a field's data.
Declaration
public abstract void VisitPartialFieldContents(ReadOnlySpan<byte> chunk)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<Byte> | chunk | The data from this part of the field. |
Remarks
This method may be called at any time.
Only VisitPartialFieldContents(ReadOnlySpan<Byte>), VisitEndOfField(ReadOnlySpan<Byte>), and VisitNonstandardQuotedField() may be called directly after a call to this method.
There are multiple reasons why this method may be called instead of going straight to calling VisitEndOfField(ReadOnlySpan<Byte>):
- Field is split across multiple read buffer chunks, or else it runs up to the very end of a read buffer chunk, but we can't prove it without the first byte of the next chunk or a ProcessEndOfStream(CsvReaderVisitorBase) call.
- Quoted field contains a literal quote that was escaped in the original stream, and so we cannot yield the entire field data as-is.
- Stream does not conform to RFC 4180, and optimizing such streams to avoid this case.