lineTerminator property

String get lineTerminator
inherited

Line ending appended by writeln, and replacing "\n" in some methods.

Must be one of the values "\n" (the default) or "\r\n".

When set to "\r\n", the methods write, writeln, writeAll and writeCharCode will convert embedded newlines, "\n", in their arguments to "\r\n". If their arguments already contain "\r\n" sequences, then these sequences will be not be converted. This is true even if the sequence is generated across different method calls.

If lineTerminator is "\n" then the written strings are not modified. Setting lineTerminator to Platform.lineTerminator will result in "write" methods outputting the line endings for the platform:

stdout.lineTerminator = Platform.lineTerminator;
stderr.lineTerminator = Platform.lineTerminator;

The value of lineTerminator has no effect on byte-oriented methods such as add.

The value of lineTerminator does not effect the output of the print function.

Throws ArgumentError if set to a value other than "\n" or "\r\n".

Implementation

//
/// Setting `lineTerminator` to [Platform.lineTerminator] will result in
/// "write" methods outputting the line endings for the platform:
///
/// ```dart
/// stdout.lineTerminator = Platform.lineTerminator;
/// stderr.lineTerminator = Platform.lineTerminator;
/// ```
///
/// The value of `lineTerminator` has no effect on byte-oriented methods
/// such as [add].
///
/// The value of `lineTerminator` does not effect the output of the [print]
/// function.
///
/// Throws [ArgumentError] if set to a value other than `"\n"` or `"\r\n"`.
String get lineTerminator => _windowsLineTerminator ? "\r\n" : "\n";
set lineTerminator (String lineTerminator)
inherited

Implementation

set lineTerminator(String lineTerminator) {
  if (lineTerminator == "\r\n") {
    assert(!_lastWrittenCharIsCR || _windowsLineTerminator);
    _windowsLineTerminator = true;
  } else if (lineTerminator == "\n") {
    _windowsLineTerminator = false;
    _lastWrittenCharIsCR = false;
  } else {
    throw ArgumentError.value(lineTerminator, "lineTerminator",
        r'invalid line terminator, must be one of "\r" or "\r\n"');
  }
}