ListToCsvConverter class

Converts rows -- a List of Lists into a csv String.

This converter follows the rules of rfc4180. Except for the possibility to override the separator character (fieldDelimiter), the text delimiter (textDelimiter) and the eol string.

The existence of a field delimiter, text delimiter or eol is determined by checking every character on it's own if the value is longer than one character.

For instance if the overridden field delimiter is '<->' and a field contains either '<' or '-' or '>' the conversion code follows the RFC as if the character the value overrides is present. (This is also the case for the default eol \r\n and follows the RFC). In this example it means, that any field which contains either '<', '-' or '>' must be quoted (rule 6).

For Rule 7 and textDelimiters with multiple characters the above statement is still correct, but only complete textDelimiter are preceded with another textDelimiter.

Ad rule 3: removed as it is not relevant for this converter. Ad rule 5: text-delimiters are only used when necessary.

Chapter 2, Definition of the CSV Format:

  1. Each record is located on a separate line, delimited by a line break (CRLF). For example: aaa,bbb,ccc CRLF zzz,yyy,xxx CRLF

  2. The last record in the file may or may not have an ending line break. For example: aaa,bbb,ccc CRLF zzz,yyy,xxx

  3. ... (Header-lines)

  4. Within the header and each record, there may be one or more fields, separated by commas. Each line should contain the same number of fields throughout the file. Spaces are considered part of a field and should not be ignored. The last field in the record must not be followed by a comma. For example:

    aaa,bbb,ccc

  5. Each field may or may not be enclosed in double quotes (however some programs, such as Microsoft Excel, do not use double quotes at all). If fields are not enclosed with double quotes, then double quotes may not appear inside the fields. For example:

    "aaa","bbb","ccc" CRLF zzz,yyy,xxx

  6. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example:

    "aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx

  7. If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote. For example:

    "aaa","b""bb","ccc"

Inheritance

Constructors

ListToCsvConverter({String fieldDelimiter = defaultFieldDelimiter, String textDelimiter = defaultTextDelimiter, String? textEndDelimiter, String eol = defaultEol, bool delimitAllFields = defaultDelimitAllFields, dynamic convertNullTo})
The default values for fieldDelimiter, textDelimiter and eol are consistent with rfc4180.
const

Properties

convertNullTo → dynamic
Use this value instead of null if a field is null.
final
delimitAllFields bool
Add delimiter to all fields, even if the field does not contain any character, which would adding delimiters necessary.
final
eol String
The end of line character which is inserted after every "row".
final
fieldDelimiter String
The separator between fields in the outputString.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textDelimiter String
The delimiter which surrounds text / fields which have a fieldDelimiter in the text representation.
final
textEndDelimiter String
final

Methods

bind(Stream<List> stream) Stream<String>
Transforms the provided stream.
override
cast<RS, RT>() StreamTransformer<RS, RT>
Provides a StreamTransformer<RS, RT> view of this stream transformer.
inherited
convert(List<List?>? rows, {String? fieldDelimiter, String? textDelimiter, String? textEndDelimiter, String? eol, bool? delimitAllFields, dynamic convertNullTo}) String
Converts rows -- a List of Lists into a csv String.
convertSingleRow(StringBuffer sb, List? rowValues, {String? fieldDelimiter, String? textDelimiter, String? textEndDelimiter, String? eol, bool? delimitAllFields, dynamic convertNullTo, bool returnString = true}) String?
Converts a list of values representing a row into a value separated string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startChunkedConversion(Sink<String> outputSink) List2CsvSink
Returns an input Sink into which the caller may add single rows. A single row is a List. The signature of the input sink is therefore: add(List).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited